Skip to content

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)

  • bullmq in package.json and a Redis connection
  • new Queue('name'), queue.add(...) and new Worker('name', processor)
  • A separate worker script in package.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

  1. Queue names, then search for every add and every Worker using each name
  2. The worker entry file and how it is started

How a request moves through the code

  1. 1Application code calls queue.add(name, data, options) with retries, delay or priority.
  2. 2BullMQ stores the job in Redis.
  3. 3A worker process picks the job up and runs the processor.
  4. 4On failure, the job is retried with backoff; after the last attempt it moves to the failed set.
  5. 5Events or listeners react to completed and failed.

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.