Node performance starts with measurement—profile before micro-optimizing. Most APIs are I/O-bound; fix N+1 queries and blocking code before tuning V8 flags.
Common bottlenecks
- Synchronous fs/crypto on hot paths
- Unbounded in-memory caches
- Missing DB indexes and N+1 ORM queries
- Huge JSON payloads without pagination
- Logging every request body at info level
Tools
node --prof/ clinic.js — CPU profiling- load testing — k6, autocannon
- APM — Datadog, New Relic, OpenTelemetry traces
Scaling strategies
Vertical scale (bigger machine), horizontal scale (multiple instances behind load balancer), caching (Redis), and async job queues for slow work.
Important interview questions and answers
- Q: When add worker threads?
A: CPU-heavy work blocking the event loop—image resize, bcrypt at high cost factor, large sync crypto. - Q: Is Node slow?
A: Wrong question—is it appropriate? I/O-heavy APIs often excel; CPU-heavy batch jobs may not.
Self-check
- Why measure before optimizing?
- What is an N+1 query problem?