Advertisement
Advanced Node.js, Background Jobs & Queues

How do you implement rate-limited job processing so a Node.js worker doesn't exceed a downstream third-party API's request limits?

Short answer

Rate limiting at the worker level throttles how many jobs are processed within a given time window (like 'no more than 100 jobs per minute'), independent of the worker's concurrency setting -- most job queue libraries support this natively (BullMQ's 'limiter' option), which is…

Save Node.js mock interview
Advertisement
AModel answer
Rate limiting at the worker level throttles how many jobs are processed within a given time window (like 'no more than 100 jobs per minute'), independent of the worker's concurrency setting -- most job queue libraries support this natively (BullMQ's 'limiter' option), which is essential when a job's actual work involves calling a third-party API with a strict rate limit, since exceeding it can trigger errors, temporary bans, or increased costs.
const worker = new Worker('sms-notifications', sendSms, {
  connection,
  limiter: {
    max: 100,     // process at most 100 jobs
    duration: 60000, // per 60-second window
  },
});
Real-world example
An SMS-notification worker calling a provider with a strict limit of 100 requests per minute configures BullMQ's built-in limiter to match exactly, ensuring the worker automatically throttles itself instead of repeatedly hitting the provider's rate limit and having messages fail or get queued for retry unnecessarily.
Likely follow-ups
  • How does queue-level rate limiting interact with a circuit breaker also wrapping the same downstream call?
  • What happens to jobs that arrive faster than the configured rate limit allows them to be processed -- do they simply wait in the queue?
Related topics