Menu

Post image 1
Post image 2
1 / 2
0

My Node.js app was making 47 database queries per request. I had no idea.

DEV Community·Sharon Alhazov·25 days ago
#bMiXe3GO
Reading 0:00
15s threshold

I'd been shipping this endpoint for 6 months. It passed code review. It passed load tests. Here's what it was actually doing. The output I added 2 lines to a realistic Express + PostgreSQL app and ran it for a few minutes under normal load. This is what printed to the console: [ QUERY ] SELECT * FROM quotes WHERE author_id = $ 1 — 47 executions in 1 . 8 s ↳ n - plus - one : quotes . service . ts : 34 fired 47 times in one request . Fix : batch with WHERE author_id = ANY ( $ 1 ) or use a dataloader . traceId : 3 a9f2b — correlated with GET / quotes / by - author ( durationMs : 2140 ms ) [ QUERY ] SELECT * FROM authors — 1 execution in 3 ms ↳ select - star : Returning all 23 columns . Hot path only uses : id , name , bio . Consider : SELECT id , name , bio FROM authors [ MEMORY ] Heap used : 187 MB → 203 MB over 60 s ↳ heap - growth : Consistent upward trend — no GC plateau detected . Check for accumulating closures or unbounded caches .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More