Node.js Rate Limits: One Worker, Batch Dispatch, and Safe Retries
A shared upstream quota, rather than the size of a batch, decides this design. Short answer: use a durable queue with one active worker for a single shared rate limit, publish batches as individually recorded jobs, and retry each logical operation with a stable idempotency key. Node.js can enforce worker concurrency 1 inside one process; it cannot make that promise across a deployment by itself.…
Node.js rate limiting requires a durable queue with a single active worker and idempotent retries. This design prioritizes durable intent, limiting concurrency to one worker, and maintaining completion evidence after each operation. The durable queue must record each item's acceptance status, including version, attempt count, next eligible time, lease expiry, and correlation ID.
The concurrency limit of one worker must accurately reflect its scope, using a single active consumer for shared or per-tenant quotas. Completion evidence should include a queue acknowledgment or HTTP success, along with a durable receipt to confirm business effects in other data stores. The key to handling idempotent retries is using a unique key for each logical operation, ensuring that the worker recognizes and handles duplicate requests appropriately.
When a 429 response is received, the server is requesting a reduction in request rate, and the Retry-After header should be respected to adhere to the recommended delay. If a request cannot be made valid, it should be rejected to prevent consuming the protected capacity.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.