<?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: Sharon Alhazov</title>
    <description>The latest articles on DEV Community by Sharon Alhazov (@concurrency).</description>
    <link>https://dev.to/concurrency</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%2F3919825%2Fbfa5b456-c930-4539-a90d-84d34866be61.png</url>
      <title>DEV Community: Sharon Alhazov</title>
      <link>https://dev.to/concurrency</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/concurrency"/>
    <language>en</language>
    <item>
      <title>My Node.js app was making 47 database queries per request. I had no idea.</title>
      <dc:creator>Sharon Alhazov</dc:creator>
      <pubDate>Fri, 08 May 2026 15:29:06 +0000</pubDate>
      <link>https://dev.to/concurrency/i-found-a-6-month-old-n1-in-my-nodejs-app-with-2-lines-of-code-4flj</link>
      <guid>https://dev.to/concurrency/i-found-a-6-month-old-n1-in-my-nodejs-app-with-2-lines-of-code-4flj</guid>
      <description>&lt;p&gt;I'd been shipping this endpoint for 6 months. It passed code review. It passed load tests. Here's what it was actually doing.&lt;/p&gt;

&lt;h2&gt;
  
  
  The output
&lt;/h2&gt;

&lt;p&gt;I added 2 lines to a realistic Express + PostgreSQL demo app and ran it for a few minutes under normal load. This is what printed to the console:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;QUERY&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;quotes&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;author_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="err"&gt;—&lt;/span&gt; &lt;span class="mi"&gt;47&lt;/span&gt; &lt;span class="n"&gt;executions&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;8&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;
&lt;span class="err"&gt;↳&lt;/span&gt; &lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;plus&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;one&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;quotes&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mi"&gt;34&lt;/span&gt; &lt;span class="n"&gt;fired&lt;/span&gt; &lt;span class="mi"&gt;47&lt;/span&gt; &lt;span class="n"&gt;times&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;one&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
   &lt;span class="n"&gt;Fix&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;batch&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="k"&gt;WHERE&lt;/span&gt; &lt;span class="n"&gt;author_id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;ANY&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="err"&gt;$&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="n"&gt;use&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="n"&gt;dataloader&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
   &lt;span class="n"&gt;traceId&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="n"&gt;a9f2b&lt;/span&gt; &lt;span class="err"&gt;—&lt;/span&gt; &lt;span class="n"&gt;correlated&lt;/span&gt; &lt;span class="k"&gt;with&lt;/span&gt; &lt;span class="k"&gt;GET&lt;/span&gt; &lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;quotes&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="k"&gt;by&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;author&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;durationMs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2140&lt;/span&gt;&lt;span class="n"&gt;ms&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;QUERY&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;authors&lt;/span&gt; &lt;span class="err"&gt;—&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="n"&gt;execution&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="n"&gt;ms&lt;/span&gt;
&lt;span class="err"&gt;↳&lt;/span&gt; &lt;span class="k"&gt;select&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;star&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Returning&lt;/span&gt; &lt;span class="k"&gt;all&lt;/span&gt; &lt;span class="mi"&gt;23&lt;/span&gt; &lt;span class="n"&gt;columns&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt; &lt;span class="n"&gt;Hot&lt;/span&gt; &lt;span class="n"&gt;path&lt;/span&gt; &lt;span class="k"&gt;only&lt;/span&gt; &lt;span class="n"&gt;uses&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bio&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
   &lt;span class="n"&gt;Consider&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bio&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;authors&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;MEMORY&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;Heap&lt;/span&gt; &lt;span class="n"&gt;used&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;187&lt;/span&gt;&lt;span class="n"&gt;MB&lt;/span&gt; &lt;span class="err"&gt;→&lt;/span&gt; &lt;span class="mi"&gt;203&lt;/span&gt;&lt;span class="n"&gt;MB&lt;/span&gt; &lt;span class="n"&gt;over&lt;/span&gt; &lt;span class="mi"&gt;60&lt;/span&gt;&lt;span class="n"&gt;s&lt;/span&gt;
&lt;span class="err"&gt;↳&lt;/span&gt; &lt;span class="n"&gt;heap&lt;/span&gt;&lt;span class="o"&gt;-&lt;/span&gt;&lt;span class="n"&gt;growth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Consistent&lt;/span&gt; &lt;span class="n"&gt;upward&lt;/span&gt; &lt;span class="n"&gt;trend&lt;/span&gt; &lt;span class="err"&gt;—&lt;/span&gt; &lt;span class="k"&gt;no&lt;/span&gt; &lt;span class="n"&gt;GC&lt;/span&gt; &lt;span class="n"&gt;plateau&lt;/span&gt; &lt;span class="n"&gt;detected&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
   &lt;span class="k"&gt;Check&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;accumulating&lt;/span&gt; &lt;span class="n"&gt;closures&lt;/span&gt; &lt;span class="k"&gt;or&lt;/span&gt; &lt;span class="n"&gt;unbounded&lt;/span&gt; &lt;span class="n"&gt;caches&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;

&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;EVENT&lt;/span&gt; &lt;span class="n"&gt;LOOP&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="n"&gt;lag&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;48&lt;/span&gt;&lt;span class="n"&gt;ms&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="n"&gt;pollDelay&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;61&lt;/span&gt;&lt;span class="n"&gt;ms&lt;/span&gt;
&lt;span class="err"&gt;↳&lt;/span&gt; &lt;span class="n"&gt;Elevated&lt;/span&gt; &lt;span class="n"&gt;above&lt;/span&gt; &lt;span class="n"&gt;baseline&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="n"&gt;ms&lt;/span&gt; &lt;span class="n"&gt;expected&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt; &lt;span class="k"&gt;Check&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;synchronous&lt;/span&gt; &lt;span class="k"&gt;work&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;request&lt;/span&gt; &lt;span class="n"&gt;handlers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fsharon77242%2FArgus%2Fmain%2Fdocs%2Fdemo.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fraw.githubusercontent.com%2Fsharon77242%2FArgus%2Fmain%2Fdocs%2Fdemo.gif" alt="Argus demo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let me explain what each one means.&lt;/p&gt;




&lt;h2&gt;
  
  
  What it found
&lt;/h2&gt;

&lt;h3&gt;
  
  
  1. The N+1 query
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;GET /quotes/by-author&lt;/code&gt; fetches a list of quotes. For each quote, it then fetches the author with a separate query.&lt;/p&gt;

&lt;p&gt;With 47 quotes in the response, that's 47 individual &lt;code&gt;SELECT * FROM quotes WHERE author_id = $1&lt;/code&gt; calls — one per row. The endpoint took &lt;strong&gt;2.1 seconds&lt;/strong&gt;. Fixed with a single batched query, it dropped to &lt;strong&gt;80ms&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;No linter catches this. No static analysis catches this. A slow endpoint in your APM dashboard gives you no cause. You have to see the query pattern at runtime.&lt;/p&gt;

&lt;h3&gt;
  
  
  2. SELECT * on a hot path
&lt;/h3&gt;

&lt;p&gt;The authors query returns 23 columns. The endpoint only renders &lt;code&gt;id&lt;/code&gt;, &lt;code&gt;name&lt;/code&gt;, and &lt;code&gt;bio&lt;/code&gt;. Every request is pulling &lt;code&gt;avatar_url&lt;/code&gt;, &lt;code&gt;created_at&lt;/code&gt;, &lt;code&gt;updated_at&lt;/code&gt;, &lt;code&gt;bio_short&lt;/code&gt;, &lt;code&gt;social_links&lt;/code&gt; (JSON), and 17 other fields — for nothing.&lt;/p&gt;

&lt;p&gt;This one is easy to miss because the query is "fast" in isolation. At scale it matters.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Heap growth
&lt;/h3&gt;

&lt;p&gt;Steady heap increase with no GC plateau means something is accumulating and not being released — an unbounded cache, event listeners not being cleaned up, or a closure keeping references alive longer than expected. The agent tracks heap size per GC cycle and flags when the trend is consistently upward with no plateau.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Event loop lag
&lt;/h3&gt;

&lt;p&gt;48ms event loop lag means the main thread is doing synchronous work somewhere in the request path. The baseline for a healthy Node.js server should be under 10ms. Above that, something is blocking the loop — a heavy computation, a synchronous file read, or a large JSON parse happening inline instead of in a worker.&lt;/p&gt;




&lt;h2&gt;
  
  
  The 2-line setup
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;argus-apm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;ArgusAgent&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;argus-apm&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;ArgusAgent&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createProfile&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;environment&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;dev&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;appType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;web&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;db&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;}).&lt;/span&gt;&lt;span class="nf"&gt;start&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Drop this at the top of your entry file and run your app under normal load for a few minutes. Findings print to the console automatically in dev mode.&lt;/p&gt;

&lt;p&gt;No account. No cloud. No config file. No side effects in production (the &lt;code&gt;dev&lt;/code&gt; profile disables console output and sampling is 100% regardless of environment).&lt;/p&gt;




&lt;h2&gt;
  
  
  How it works
&lt;/h2&gt;

&lt;p&gt;The agent hooks into &lt;a href="https://nodejs.org/api/diagnostics_channel.html" rel="noopener noreferrer"&gt;&lt;code&gt;node:diagnostics_channel&lt;/code&gt;&lt;/a&gt; — Node's official observability primitive, stable since Node 18. No monkey-patching, no prototype pollution, no changes to your existing code beyond the 2-line setup.&lt;/p&gt;

&lt;p&gt;For N+1 detection: it tracks query fingerprints per HTTP transaction. If the same fingerprint fires repeatedly from the same call site in one request window, it flags it with file and line number.&lt;/p&gt;

&lt;p&gt;For privacy: SQL values are destroyed at the AST layer before any metric is recorded. Not redacted from logs — shredded before they exist as data.&lt;/p&gt;

&lt;p&gt;Supported drivers: &lt;code&gt;pg&lt;/code&gt;, &lt;code&gt;mysql2&lt;/code&gt;, &lt;code&gt;mongodb&lt;/code&gt;, &lt;code&gt;redis&lt;/code&gt;, &lt;code&gt;ioredis&lt;/code&gt;, &lt;code&gt;prisma&lt;/code&gt;, &lt;code&gt;typeorm&lt;/code&gt;, &lt;code&gt;sequelize&lt;/code&gt;, &lt;code&gt;mongoose&lt;/code&gt;, &lt;code&gt;sqlite3&lt;/code&gt;, &lt;code&gt;better-sqlite3&lt;/code&gt;, &lt;code&gt;mariadb&lt;/code&gt;, &lt;code&gt;cassandra-driver&lt;/code&gt;, &lt;code&gt;tedious&lt;/code&gt;, &lt;code&gt;oracledb&lt;/code&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  Try it on your app
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;argus-apm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Point it at a real project — not a hello world. Run it for 5 minutes under actual traffic. See what it finds.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What did it catch in your codebase?&lt;/strong&gt; Drop your result in the GitHub Discussion — driver, framework, what it found. Even "found nothing" is useful data and takes 30 seconds to post.&lt;/p&gt;

&lt;p&gt;→ &lt;a href="https://github.com/sharon77242/Argus/discussions" rel="noopener noreferrer"&gt;Share what Argus found →&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;→ &lt;a href="https://github.com/sharon77242/Argus" rel="noopener noreferrer"&gt;GitHub repo&lt;/a&gt;&lt;/p&gt;

</description>
      <category>node</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
