BullMQ is an open-source job queue library for Node.js that stores jobs in Redis and lets separate worker processes execute them asynchronously, with built-in support for delays, retries, priorities, rate limits and recurring schedules. In scheduling for automation, it is the component that turns a request such as “send this invoice reminder in three days” or “rebuild the search index every night” into a durable, observable unit of work that survives process restarts.
BullMQ is the TypeScript rewrite and successor of the older Bull library. It keeps the same Redis-centric design but adds parent-child job flows, a cleaner event model and job schedulers for cron-style recurrence. Official ports exist for Python, Elixir and PHP, so producers and workers written in different languages can share the same queues.
How BullMQ moves a job from producer to worker
BullMQ separates the code that creates jobs from the code that processes jobs, and Redis sits between them as the shared state. A producer calls queue.add() with a job name and a JSON payload; a Worker instance subscribed to the same queue name picks the job up, runs a processor function and records the result.
Every state change is executed by atomic Lua scripts inside Redis, which is why two workers never receive the same job at the same moment. When a worker takes a job, it acquires a lock with a lock duration (30 seconds by default) and renews it while the processor runs. If the worker crashes and the lock expires, a periodic check marks the job as stalled and returns it to the waiting list, so another worker can take over.
This design gives at-least-once delivery, not exactly-once delivery. A job whose worker died after doing the real work but before recording completion will run again, so processors must be idempotent or must check whether the side effect already happened.
The following table lists the main building blocks and the role each one plays.
| Component | Role | Typical location |
|---|---|---|
| Queue | Adds jobs and manages queue-level settings | API server or scheduler process |
| Worker | Fetches jobs and runs the processor function | Dedicated background process |
| QueueEvents | Streams global events such as completed or failed | Monitoring or notification service |
| FlowProducer | Creates trees of parent and child jobs atomically | Orchestration code |
| Job scheduler | Generates jobs on a cron pattern or fixed interval | Defined once at startup |
Job states and lifecycle in BullMQ
A BullMQ job always sits in exactly one well-defined state, and each state is a separate Redis structure that tools and dashboards can inspect. Understanding these states is the key to diagnosing stuck or lost jobs in production.
| State | Meaning | Leaves the state when |
|---|---|---|
| Waiting | Ready to run, ordered first in, first out | A worker fetches it |
| Prioritized | Ready to run, ordered by priority number | A worker fetches it |
| Delayed | Scheduled for a future timestamp | The delay expires |
| Waiting-children | Parent job waiting for its child jobs | All children complete |
| Active | Locked and being processed | Processor resolves, throws or stalls |
| Completed | Finished with a stored return value | Removed by retention rules |
| Failed | Exhausted all attempts or failed permanently | Retried manually or removed |
Completed and failed jobs remain in Redis until retention settings remove them. Without removeOnComplete and removeOnFail limits, a busy queue can fill Redis memory with millions of finished jobs, a common cause of slow dashboards and eviction incidents.
Scheduling features: delays, priorities and recurrence
BullMQ covers the main scheduling patterns of background processing through job options rather than separate services. A delayed job uses the delay option in milliseconds and moves to the waiting state when its time arrives; precision is typically within tens of milliseconds, not real-time guarantees.
Recurring jobs are defined with upsertJobScheduler(), which accepts either a cron expression with an optional time zone or an every interval. The scheduler creates only the next occurrence at a time, so a missed window does not produce a burst of duplicate jobs. Earlier versions used repeatable jobs, which are now deprecated in favor of job schedulers.
The table below maps common requirements to the option that implements them.
| Requirement | BullMQ option | Behavior |
|---|---|---|
| Run later | delay | Job enters the delayed set until its timestamp |
| Run regularly | upsertJobScheduler() | Cron pattern or fixed interval, one job at a time |
| Run urgent work first | priority | Lower number runs earlier; 0 means no priority |
| Retry after failure | attempts and backoff | Fixed or exponential delay between attempts |
| Throttle an external API | Worker limiter | At most a set number of jobs per time window |
| Run after other jobs | FlowProducer children | Parent waits until every child completes |
| Drop duplicate requests | deduplication | Ignores new jobs with the same identifier |
Concurrency is controlled at two levels. The worker concurrency option sets how many jobs one worker process runs in parallel, while global concurrency on the queue caps the total across all workers, which protects databases and third-party APIs from overload.
How BullMQ compares with other job schedulers
BullMQ belongs to the family of language-specific queue libraries that rely on a broker or store, alongside Celery, Sidekiq and Hangfire. It differs from enterprise workload automation tools such as Control-M, which manage cross-system batch calendars rather than application-level jobs.
| Tool | Main language | State kept in | Distinctive trait |
|---|---|---|---|
| BullMQ | TypeScript with official ports | Redis, Valkey or Dragonfly | Parent-child flows and job schedulers |
| Celery | Python | A message broker plus result backend | Canvas primitives for chains and groups |
| Sidekiq | Ruby | Redis | Thread-based workers for Rails |
| Hangfire | .NET | SQL Server or other storage | Dashboard bundled with the library |
| Quartz Scheduler | Java | RAM store or JDBC store | Rich trigger calendars |
| Control-M | Any | Central enterprise server | Cross-system batch calendars |
Compared with a plain cron table, BullMQ adds persistence, retries, horizontal scaling and visibility. Compared with a durable workflow engine, it offers simpler parent-child flows but no automatic replay of long-running, multi-step business logic.
Operating BullMQ reliably in production
Most BullMQ incidents come from Redis configuration and job design, not from the library itself. Redis must run with the maxmemory-policy set to noeviction, because an eviction policy can silently delete job keys and corrupt queue state.
| Symptom | Likely cause | Fix |
|---|---|---|
| Jobs run twice | Stalled lock after long CPU-bound work | Use sandboxed processors or longer lock duration |
| Queue keys disappear | Redis eviction policy enabled | Set noeviction and monitor memory |
| Redis memory grows steadily | No retention for finished jobs | Configure removeOnComplete and removeOnFail |
| Cluster errors on scripts | Keys spread across hash slots | Use a hash tag in the queue prefix |
| Jobs lost on deploy | Workers killed without shutdown | Call worker.close() on termination signals |
- Keep payloads small and store large data elsewhere, passing only identifiers in the job.
- Run CPU-heavy processors as sandboxed processors in separate processes so the event loop can renew locks.
- Distinguish retryable and permanent errors; throw an
UnrecoverableErrorwhen retrying cannot help. - Monitor queue depth, failure rate and job latency with a dashboard or exported metrics.
The simple explanation
BullMQ works like a shared task board in a repair shop. The front desk clerk puts a card for each broken device on the board and goes back to serving customers. Technicians pull cards from the board whenever they are free. If a technician leaves early, the unfinished card goes back on the board for a colleague.
In software, the website is the clerk, the background programs are the technicians and Redis is the board. BullMQ adds useful rules: some cards wait until a set date, urgent cards go first, and failed repairs are tried again. The main benefit is that slow work never blocks the user.
How it is used in practice
An online learning platform built on Node.js sends course certificates, weekly progress emails and video transcoding tasks. When a student finishes a course, the API adds a generate-certificate job to BullMQ and answers the student immediately instead of waiting several seconds for the PDF.
The team runs four worker processes with a concurrency of 10 each for email jobs, and a limiter of 50 jobs per second to stay within the email provider quota. A job scheduler with the cron pattern 0 7 * * MON in the students’ time zone creates the weekly digest. Failed emails retry five times with exponential backoff starting at 2 seconds.
After a Redis memory alert, the team set retention to keep the last 1,000 completed jobs and 7 days of failed jobs. Memory use dropped by about 80 percent, and the failed-job list became a practical tool for support staff investigating missing certificates.