Your Node.js API handles 10,000 requests per second on a Friday afternoon. By Monday, it's crawling at 200 RPS with 500ms latency. No code changed. No traffic spike. Just the silent accumulation of unoptimized patterns that finally hit the wall.
Profile Before You Optimize
Guessing wastes time. Use node --inspect with Chrome DevTools or clinic.js for flame graphs. Identify the actual bottlenecks: CPU-bound event loop blockers, memory leaks, or synchronous I/O masquerading as async.
Event Loop: Keep It Unblocked
The event loop is single-threaded. Any synchronous operation over 10ms blocks everything. Move CPU-heavy work to Worker Threads or offload to dedicated services.
Clustering: Use All Cores
Node runs on one core by default. Use the built-in cluster module or PM2 to fork workers equal to CPU cores. Share nothing; communicate via message passing or Redis.
Caching Layers That Actually Work
Three layers minimum: HTTP cache headers (ETag, Cache-Control), in-memory LRU for hot data, Redis for distributed caching. Invalidate on write, not on timer.
Database: Connection Pooling & Query Optimization
Never open connections per request. Configure pool sizing: min: 2, max: 10 per worker. Use prepared statements. Add indexes for query patterns. Monitor slow query logs religiously.
| Pool Setting | Recommendation |
|---|---|
| min | 2 per worker |
| max | 10 per worker |
| idleTimeout | 30000ms |
| acquireTimeout | 60000ms |
Memory Leaks: The Silent Killers
Global arrays, unclosed streams, event listeners never removed. Set --max-old-space-size=1024 as a guardrail. Use heapdump or memwatch-next to compare snapshots.
Stream Processing Over Buffering
Large files or payloads? Stream them. Buffering 500MB into memory crashes the process. Use pipeline for backpressure handling.
Production Hardening Checklist
Enable compression, helmet, rate limiting. Set NODE_ENV=production. Use graceful shutdown with SIGTERM handling. Health checks must verify dependencies, not just process liveness.
"Performance is not a feature you add later. It's a constraint you design for from day one.
— Backend Engineer
✦
Start today: run clinic doctor on your busiest endpoint. Fix the top finding. Deploy. Measure. Repeat. That's how you go from 200 RPS back to 10,000.










