<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Amitwebdev on Medium]]></title>
        <description><![CDATA[Stories by Amitwebdev on Medium]]></description>
        <link>https://medium.com/@amitwebdev2019?source=rss-3e46ea0ad3bb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*dSzhsvUzuj9OrC9h</url>
            <title>Stories by Amitwebdev on Medium</title>
            <link>https://medium.com/@amitwebdev2019?source=rss-3e46ea0ad3bb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 10:27:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@amitwebdev2019/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Concurrency vs Parallelism]]></title>
            <link>https://medium.com/@amitwebdev2019/concurrency-vs-parallelism-80ad1595b416?source=rss-3e46ea0ad3bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/80ad1595b416</guid>
            <dc:creator><![CDATA[Amitwebdev]]></dc:creator>
            <pubDate>Sat, 24 Jun 2023 08:44:28 GMT</pubDate>
            <atom:updated>2023-06-24T11:47:43.207Z</atom:updated>
            <content:encoded><![CDATA[<p>When I started my career as a developer, I was used to node.js. Whenever i needed to make different async calls, I was doing it wrong. i was waiting for the first promise to be completed and then started executing the next promise or function call, even though they are not dependent on each other. Then my senior told me to use the promise.all method in Javascript. while studying promise.All methods taught me about concurrency, but at that point in time I was new to concurrency and parallelism. So here are some things that I understand about concurrency and parallelism.</p><p><strong>Concurrency: </strong>handling multiple things at the same time. Concurrency is about multiple tasks that start, run, and complete in overlapping time periods, in no specific order. Concurrency is a method that requires only a single processing unit to accomplish a task.</p><p><strong>Parallelism:</strong> doing multiple things at the same time.Parallelism is about multiple tasks or subtasks of the same task that literally run at the same time on hardware with multiple computing resources, like a multi-core processor.The technique in which multiple processors are used to accomplish multiple computations simultaneously is known as parallelism.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80ad1595b416" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to fetch random tuples from Postgres?]]></title>
            <link>https://medium.com/@amitwebdev2019/how-to-fetch-random-tuples-from-postgres-cc279d4261cd?source=rss-3e46ea0ad3bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/cc279d4261cd</guid>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[tuples]]></category>
            <dc:creator><![CDATA[Amitwebdev]]></dc:creator>
            <pubDate>Sat, 17 Dec 2022 10:19:42 GMT</pubDate>
            <atom:updated>2022-12-17T17:41:51.591Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*N4V-V9m4hmJNNrZ92y0TOQ.jpeg" /></figure><p>Last week in my project I need to fetch random tuples from the table, so I started looking for them. I am writing this blog to share what I learned from it. A couple of interesting things I got to know about Postgres. Postgres has its unique way to deal with this problem. let’s discuss this in the following section.</p><p><strong><em>1 ] Order by Random :</em></strong></p><pre>SELECT * FROM &quot;table_name&quot; ORDER BY RANDOM() LIMIT 10;</pre><p>This is a more common way to fetch random tuples from Postgres, but this method is slightly slow. When Postgres start executing the above statement, it needs to do, a sequential scan, also it needs to run two more loops first for limit and second for sorting, which takes approximately <strong>555.743 ms</strong> for <strong>1 million</strong> records.</p><p><strong><em>2] Random with where clause :</em></strong></p><pre>SELECT * FROM &quot;table_name&quot; where random() &lt; 0.1 LIMIT 10;</pre><p>This one is best for achieving the random rows in constant time. In this scenario, Postgres does not need to sort the records. also, it does a sequential scan which takes approximately 100 ms for 1m records. This method returns random records on the row level rather than the page level. Under the hood Postgres reads random blocks from the disk and returns a few rows from it, that’s why we could not control the number of rows.</p><p>This is the only way in Postgres to archive truly random rows from the table. if you increase the number from 0.1 to any then you got more continuous rows which are not expected. Basically, it totally depends on how you gone store your data.</p><p><strong>3] Tablesample :</strong></p><pre>CREATE EXTENSION tsm_system_rows;<br><br>SELECT * FROM &quot;table_name&quot; TABLESAMPLE SYSTEM_ROWS(10)</pre><p>This is one of the fastest ways to fetch random tuples from the database. This way takes approximately 0.05 seconds for 1m records. Let’s explore how table sample works. What basically it does it will read random pages from the disk by looking at the total pages, and start reading from them. This will start reading from those pages in a such way it will return the continuous rows from the table.</p><p><strong>Conclusion :</strong></p><ul><li>ORDER BY random() is slow because of sorting.</li><li>random() &lt;= 0.1 is faster than ORDER BY random()</li><li>SYSTEM is fast but it’s hard to control the number of rows</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cc279d4261cd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to properly set env configuration in nestjs]]></title>
            <link>https://medium.com/@amitwebdev2019/how-to-properly-set-env-configuration-in-nestjs-bdf30f7827ae?source=rss-3e46ea0ad3bb------2</link>
            <guid isPermaLink="false">https://medium.com/p/bdf30f7827ae</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nestjs]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[env-variable]]></category>
            <dc:creator><![CDATA[Amitwebdev]]></dc:creator>
            <pubDate>Sat, 19 Nov 2022 19:15:27 GMT</pubDate>
            <atom:updated>2022-11-19T19:15:27.277Z</atom:updated>
            <content:encoded><![CDATA[<p>Recently i foun, there are many ways that nestjs offers to do application configuration. but i found the better way to deal with this problem.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bdf30f7827ae" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>