BullMQ

On this page 7

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.

ComponentRoleTypical location
QueueAdds jobs and manages queue-level settingsAPI server or scheduler process
WorkerFetches jobs and runs the processor functionDedicated background process
QueueEventsStreams global events such as completed or failedMonitoring or notification service
FlowProducerCreates trees of parent and child jobs atomicallyOrchestration code
Job schedulerGenerates jobs on a cron pattern or fixed intervalDefined once at startup
Core BullMQ components

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.

StateMeaningLeaves the state when
WaitingReady to run, ordered first in, first outA worker fetches it
PrioritizedReady to run, ordered by priority numberA worker fetches it
DelayedScheduled for a future timestampThe delay expires
Waiting-childrenParent job waiting for its child jobsAll children complete
ActiveLocked and being processedProcessor resolves, throws or stalls
CompletedFinished with a stored return valueRemoved by retention rules
FailedExhausted all attempts or failed permanentlyRetried manually or removed
Job states a BullMQ job can occupy

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.

RequirementBullMQ optionBehavior
Run laterdelayJob enters the delayed set until its timestamp
Run regularlyupsertJobScheduler()Cron pattern or fixed interval, one job at a time
Run urgent work firstpriorityLower number runs earlier; 0 means no priority
Retry after failureattempts and backoffFixed or exponential delay between attempts
Throttle an external APIWorker limiterAt most a set number of jobs per time window
Run after other jobsFlowProducer childrenParent waits until every child completes
Drop duplicate requestsdeduplicationIgnores new jobs with the same identifier
Scheduling options and their effect

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.

ToolMain languageState kept inDistinctive trait
BullMQTypeScript with official portsRedis, Valkey or DragonflyParent-child flows and job schedulers
CeleryPythonA message broker plus result backendCanvas primitives for chains and groups
SidekiqRubyRedisThread-based workers for Rails
Hangfire.NETSQL Server or other storageDashboard bundled with the library
Quartz SchedulerJavaRAM store or JDBC storeRich trigger calendars
Control-MAnyCentral enterprise serverCross-system batch calendars
Where BullMQ differs from similar tools

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.

SymptomLikely causeFix
Jobs run twiceStalled lock after long CPU-bound workUse sandboxed processors or longer lock duration
Queue keys disappearRedis eviction policy enabledSet noeviction and monitor memory
Redis memory grows steadilyNo retention for finished jobsConfigure removeOnComplete and removeOnFail
Cluster errors on scriptsKeys spread across hash slotsUse a hash tag in the queue prefix
Jobs lost on deployWorkers killed without shutdownCall worker.close() on termination signals
Common problems and fixes
  • 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 UnrecoverableError when 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.