Job Concurrency and Rate Limiting

Configure BullMQ Worker concurrency and queue rate limits to manage the load on resources and external services.

🎯 Introduction

By the end of this article, you will be able to process multiple jobs concurrently and limit how many jobs a queue starts within a time window.

Reuse the Redis configuration and queue-config.mjs from the BullMQ quick start. This course uses BullMQ 5.61.2.


🧱 Concurrency vs. Rate Limiting

Concurrency limits how many jobs are being processed at once; rate limiting caps how many jobs can start within a time window. The former controls simultaneous resource use, while the latter controls how frequently jobs start.

For example, limit concurrency when file processing is constrained by memory. Limit the rate when an external service caps requests per minute. You can use both together.


⚡ Worker Concurrency

concurrency is the number of jobs a single Worker can process at once. Create concurrent-worker.mjs to observe overlapping processing:

concurrent-worker.mjs
import { Worker } from 'bullmq';
import { setTimeout as delay } from 'node:timers/promises';
import { connection, queueName } from './queue-config.mjs';

async function processJob(job) {
    console.log('Started:', job.id);
    await delay(2000);
    console.log('Completed:', job.id);
}

const worker = new Worker(queueName, processJob, {
    connection: { ...connection, maxRetriesPerRequest: null },
    concurrency: 2,
});
worker.on('failed', (job, error) => console.error(job?.id, error.message));
worker.on('error', error => console.error(error.message));
process.once('SIGINT', async () => { await worker.close(); });

The 2-second wait simulates a job that spends time waiting. A concurrency of 2 lets the Worker process at most two jobs at once; it does not automatically make synchronous JavaScript computations use two CPU cores.

Submit three jobs, then start the Worker:

node add-job.mjs
node add-job.mjs
node add-job.mjs
node concurrent-worker.mjs

The terminal typically shows two “Started” messages first. The third job starts after one of those jobs finishes. Completion order may differ from submission order.


🧰 Sharing Work Across Workers

Multiple Workers can pick up jobs from the same queue. Each Worker's concurrency setting applies independently, so two Workers with concurrency: 2 may process up to four jobs at once.

This suits jobs that wait for network or file operations when downstream systems have enough capacity. Before adding Workers, check database connection limits, memory, and external service quotas. Increasing concurrency can also increase downstream load.

CPU-intensive jobs occupy the JavaScript execution thread. Simply increasing concurrency in one process may not provide parallel computation. Use separate processes or a dedicated threading approach when you need more CPU capacity.


🚦 Queue Rate Limiting

BullMQ rate limiting controls the start rate across the whole queue, rather than just one Worker. This is useful when an external API limits requests per second.

Add these options to the Worker configuration in concurrent-worker.mjs:

limiter: {
    max: 5,
    duration: 1000,
},

max is the maximum number of jobs that can start within the time window, and duration is measured in milliseconds. This configuration allows the queue to start at most 5 jobs per second. Completion throughput still depends on concurrency and processing time.

In BullMQ 5, limiter is configured on Workers, but the quota is coordinated across the queue. Workers on the same queue share this rate limit. See BullMQ rate limiting.


🧰 Choose Settings for Your Jobs and Downstream Capacity

Base concurrency on the resources each job consumes, and base rate limits on external service quotas. Monitor waiting jobs, active jobs, and downstream errors, then adjust gradually. Idle CPU alone is not a reason to keep increasing concurrency.


❓ Knowledge Check

Q1: Does concurrency of 5 guarantee only 5 jobs run per second?

No. It limits the number of active jobs at once. A rate limit constrains how many jobs start within a time window.

Q2: What is the queue's concurrency with two Workers configured for concurrency of 3?

Without other limits, up to 6 jobs may be processed at once.

Q3: Can CPU-intensive jobs be accelerated just by increasing concurrency?

Not necessarily. When CPU computations occupy the same JavaScript thread, other jobs' processing callbacks must wait too.


🧪 Exercise

Set concurrency: 1, then change it to 3. Submit several jobs and compare how the “Started” and “Completed” logs interleave.

// Write your code here

🎉 You now understand concurrency and rate limiting!