Interview Prep Guide
Node.js Production Backend Interview Questions
Production Node.js questions on event-loop health, streams, workers, APIs, security, observability, testing, and graceful shutdown.
Applied Node.js Questions
How does backpressure work in Node.js streams?
Backpressure prevents a fast producer from overwhelming a slower consumer by coordinating when more data should be read or written.
When should Node.js use worker threads?
Use workers for measured CPU-bound JavaScript work that would otherwise block the event loop, not ordinary asynchronous I/O.
How should an API validate and normalize input?
Validate at the trust boundary with explicit schemas, size limits, clear errors, and normalization that does not hide invalid or unauthorized values.
Advanced Node.js Questions
How do you prevent event-loop starvation in a Node.js service?
Measure event-loop delay, break or move CPU-heavy work, bound concurrency, stream large payloads, and avoid synchronous operations on request paths.
What should graceful shutdown do in a Node.js API?
Stop accepting traffic, fail readiness, drain in-flight work within a deadline, close resources, flush essential telemetry, and then exit.
How would you secure outbound requests from a Node.js service?
Validate destinations, use allowlists where possible, block private-network abuse, apply timeouts and size limits, and avoid forwarding secrets across redirects.
How should errors be modeled across a Node.js service?
Use a small typed error taxonomy that separates expected client, dependency, retryable, and internal failures while preserving causes privately.
Node.js Production Scenarios
Latency rises while CPU and memory look normal. How would you investigate?
Inspect downstream timing, connection pools, DNS, event-loop delay, queueing, timeouts, and percentile traces instead of relying on host averages.
A webhook is delivered multiple times. How should the service behave?
Verify authenticity, persist an idempotency key or event identity, make processing repeatable, and acknowledge according to the provider contract.
Additional Frequently Tested Questions
How do you detect event-loop blocking in Node.js?
Measure event-loop delay and utilization, correlate slow intervals with CPU profiles, and inspect synchronous work, large serialization, regex behavior, or oversized callbacks.
How do streams provide backpressure in Node.js?
A writable stream signals when its buffer is full, and producers should pause until capacity returns instead of continuing to allocate data.
When should Node.js worker threads be used?
Use workers for CPU-intensive JavaScript that would otherwise block the main event loop, not as a default solution for ordinary asynchronous I/O.
How should a Node.js service handle unhandled errors?
Record enough safe context, stop accepting work when process state may be unsafe, drain what can be completed, and let supervision restart the process.
How do you diagnose growing memory use in a Node.js process?
Compare post-garbage-collection heap over time, capture heap snapshots, inspect retaining paths, and correlate growth with traffic or feature activity.
How should AsyncLocalStorage be used safely?
Use it to carry request-scoped context such as trace identifiers across asynchronous calls without passing that value through every function.