Node.js Developer interview question · Most asked
How do you implement rate limiting in a Node.js API?
Summary
Use middleware (express-rate-limit, @fastify/rate-limit) backed by Redis for multi-instance deployments, with algorithms like fixed window, sliding window or token bucket, keyed by API key, user ID or client IP, and return 429 with Retry-After.
Longer Answer
Configure trust proxy correctly so req.ip is the real client IP behind load balancers. Apply stricter limits to auth endpoints, and add edge rate limiting (CDN/WAF) for volumetric attacks.
Key Points
- Redis-backed shared limits
- Key by user/API key/IP
trust proxyfor real IPs- 429 +
Retry-After
More most-asked Node.js Developer questions
- Why is CPU-bound work a problem in Node.js and how do you handle it?
- What are streams in Node.js and what is backpressure?
- What is the difference between `process.nextTick`, Promise microtasks, `setImmediate` and `setTimeout(fn, 0)`?
- Explain the phases of the Node.js event loop.
- What is Node.js and why is it well suited to I/O-heavy servers?
- How has asynchronous code evolved in Node.js: callbacks, Promises and async/await?
- Walk through how an Express app handles a request, including errors from async handlers.
- What are the differences between CommonJS and ES modules in Node.js?