<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Md Abdur Razzak</title>
    <description>The latest articles on DEV Community by Md Abdur Razzak (@md_abdurrazzak_e15e97412).</description>
    <link>https://dev.to/md_abdurrazzak_e15e97412</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1854892%2F6e56d7fd-7fbe-41eb-a9ed-8e8f1eef12b2.png</url>
      <title>DEV Community: Md Abdur Razzak</title>
      <link>https://dev.to/md_abdurrazzak_e15e97412</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/md_abdurrazzak_e15e97412"/>
    <language>en</language>
    <item>
      <title>How I Made My API 40% Faster with Just One Change</title>
      <dc:creator>Md Abdur Razzak</dc:creator>
      <pubDate>Thu, 14 Aug 2025 11:43:56 +0000</pubDate>
      <link>https://dev.to/md_abdurrazzak_e15e97412/how-i-made-my-api-40-faster-with-just-one-change-12ni</link>
      <guid>https://dev.to/md_abdurrazzak_e15e97412/how-i-made-my-api-40-faster-with-just-one-change-12ni</guid>
      <description>&lt;p&gt;The other day, I was working on an API in Node.js + MongoDB.&lt;/p&gt;

&lt;p&gt;I had to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check if a user exists&lt;/li&gt;
&lt;li&gt;Get all their successful payment records&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;The normal way?&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
const user = await User.findOne({ email: userEmail });
const payments = await Payment.find({ user: userEmail, status.successful });

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This runs &lt;strong&gt;one after another.&lt;/strong&gt; Slow. 😴&lt;/p&gt;

&lt;p&gt;Then I remembered something simple but powerful which is &lt;strong&gt;Promise.all()&lt;/strong&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const [user, successfulPayments] = await Promise.all([
  User.findOne({ email: userEmail }),
  Payment.find({ user: userEmail, status.successful })
]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now both queries run at the same time.&lt;br&gt;
If one takes 150ms and the other 200ms → my API returns in 200ms instead of 350ms.&lt;/p&gt;

&lt;p&gt;💡 When to use Promise.all()&lt;br&gt;
✅ When your async tasks don’t depend on each other&lt;br&gt;
✅ When you want to save time by running them in parallel&lt;br&gt;
⚠ If one fails, they all fail — so always handle errors&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;try {
  const [user, successfulPayments] = await Promise.all([
    User.findOne({ email: userEmail }),
    Payment.find({ user: userEmail, status: status.successful })
  ]);
  console.log("=================&amp;gt; User email", successfulPayments)
} catch (error) {
  console.error(error);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Sometimes performance boosts don’t come from complex algorithms&lt;br&gt;
they come from knowing the right tool at the right time. &lt;/p&gt;

&lt;p&gt;Do you use Promise.all() in your APIs? Or are you still running things one after another?&lt;/p&gt;

</description>
      <category>express</category>
      <category>node</category>
      <category>backend</category>
      <category>mongodb</category>
    </item>
  </channel>
</rss>
