How to understand a BullMQ (job queues) codebase
BullMQ moves work out of the request path. One part of the code adds jobs to a queue, and a separate worker process picks them up from Redis. The producer and the worker are often in different folders or even different deployments.
How to tell it's BullMQ (job queues)
bullmqinpackage.jsonand a Redis connectionnew Queue('name'),queue.add(...)andnew Worker('name', processor)- A separate
workerscript inpackage.json
Where things usually live
- src/queues/
- Queue definitions and helpers that add jobs.
- src/workers/ or src/jobs/
- Workers and processor functions.
- src/worker.ts
- The entry for the worker process.
- src/lib/redis.ts
- Shared connection settings.
Conventions, not rules. Real projects rename and move things, so confirm against the repository.
Where to start reading
- Queue names, then search for every
addand everyWorkerusing each name - The worker entry file and how it is started
How a request moves through the code
- Application code calls
queue.add(name, data, options)with retries, delay or priority. - BullMQ stores the job in Redis.
- A worker process picks the job up and runs the processor.
- On failure, the job is retried with backoff; after the last attempt it moves to the failed set.
- Events or listeners react to
completedandfailed.
Questions to ask about the repository
- List every queue, what adds to it and which worker processes it.
- What retry and backoff settings does each job type use?
- Which jobs are repeatable or scheduled?
What trips people up
- If the worker process isn't running, jobs pile up silently; check how workers are deployed.
- Job data is serialised to JSON, so class instances and dates lose their types.
- Processors should be idempotent, because retries can run the same job twice.