Back to results for “Profiling”
Node.js › Background Jobs & Queues

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

Intermediate

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.

Common 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?