Advertisement
Intermediate Node.js, Background Jobs & Queues

What is job concurrency in a worker process, and how do you configure it safely in BullMQ?

Short answer

Job concurrency controls how many jobs a single worker process handles simultaneously -- BullMQ workers are inherently concurrent for I/O-bound job handlers (since Node's event loop can juggle multiple in-flight async operations), configurable via the 'concurrency' option, but…

Save Node.js mock interview
Advertisement
AModel answer
Job concurrency controls how many jobs a single worker process handles simultaneously -- BullMQ workers are inherently concurrent for I/O-bound job handlers (since Node's event loop can juggle multiple in-flight async operations), configurable via the 'concurrency' option, but setting it too high risks exhausting downstream resources (database connections, memory, external API rate limits) that all concurrently running jobs compete for.
const worker = new Worker('emails', async (job) => {
  await sendEmail(job.data);
}, {
  connection,
  concurrency: 10, // up to 10 email jobs processed simultaneously by this worker
});
Real-world example
An email-sending worker initially set its concurrency to 50, quickly exhausting its email provider's connection pool and triggering rate-limit errors; lowering it to 10 (matched to the provider's documented concurrent-connection limit) resolved the errors while still processing the backlog quickly.
Likely follow-ups
  • How do you determine the right concurrency value for a given downstream dependency's actual capacity?
  • How does concurrency interact with horizontal scaling -- running more worker processes versus raising concurrency within one?
Related topics