Quick answer

BullMQ is a Node.js job queue backed by Redis: your web code adds a job to a queue, and a worker runs it, so slow work never blocks a web request. This post sends three shop orders through a BullMQ queue, charges the two good ones, and watches the third fail and retry because its total is missing.

A customer in Karachi clicks buy on a small online shop. The checkout code charges the card, updates stock, and sends a confirmation email, all inside one web request. Then the email service stalls, the request times out, and the customer clicks buy again. The card is charged twice, and the shop owner hears about it from an angry customer, not a log. A queue breaks that chain. The web request only records the order and hands it to BullMQ, and a worker charges it and sends the email in its own time. If the worker crashes halfway, the order still sits in Redis, waiting for the next worker.

What I would check before using it

My first check: does the work need to outlive the web request? An email, a charge, or a report can take seconds, while a web request should answer fast. When the slow step can fail on its own, a queue earns its place. A quick database write needs only plain code in the handler. For same-time work in one process, plain async code may be simpler; the Node.js REST API post shows where that handler lives.

My second check is who runs Redis. BullMQ stores every job in Redis, so the queue is only as reliable as that server. If nobody owns it, a managed Redis is the honest alternative. Redis is one more service to run, and the Redis Explained: The In-Memory Store That Speeds Things Up post covers what it does.

My third check is what happens when a job fails. Every queue needs a plan for the job that can never succeed: how many retries, how long to wait, and where failures are recorded. Without one, a bad job retries forever while good orders wait. The demo allows three attempts, then fails for good.

My fourth check: are the jobs safe to run twice? A worker can crash after charging a card but before recording it, and BullMQ may run it again. If charging twice is a disaster, the job needs an idempotency key checked before charging.

My verdict, as judgement: adopt BullMQ when background work must not block the user and must survive a crash, and the team runs Node.js and Redis. Skip it for a small script. The recommendation flips the moment nobody owns Redis, or the queue costs more than the job.

Three orders, one worker, and a missing total

Three orders arrive at the same small shop. Ayesha buys a kurta and a dupatta for Rs 12,400, Bilal buys sneakers for Rs 7,800, and Hina buys a handbag and a wallet with no total.

One file defines the queue and the worker, pointing at a local Redis on port 6379. The job checks the total, waits one second to stand in for the charge, and returns a receipt. Every job gets three attempts, one second apart.

/** * Order queue for The Practical Developer (BullMQ demo). * * A small online shop sends each order to a BullMQ queue backed by * Redis instead of charging the card inside the web request. A worker * picks each job up, charges the order, and returns a receipt string. * One order arrives without a total, so the worker throws, BullMQ * retries it twice, and then the job fails for good. * * Run from this folder: * node dispatch_first.js (sends order 101, no worker running) * node worker.js (start the worker in another terminal) * node dispatch_rest.js (sends orders 102 and 103, waits for results) */ const { Queue, Worker, QueueEvents } = require("bullmq"); const connection = { host: "127.0.0.1", port: 6379 }; function makeQueue() { return new Queue("shop-orders", { connection }); } async function processOrder(job) { const { orderId, customer, items, total } = job.data; if (total === undefined || total === null) { throw new Error(`order ${orderId} has no total to charge`); } if (total <= 0) { throw new Error(`order ${orderId} has an invalid total: ${total}`); } await new Promise((resolve) => setTimeout(resolve, 1000)); const joined = items.join(", "); return ( `Order ${orderId} for ${customer}: charged Rs ${total} ` + `for ${joined}; confirmation email queued` ); } function makeWorker() { const worker = new Worker("shop-orders", processOrder, { connection, concurrency: 1, }); worker.on("completed", (job, result) => { console.log(`Worker: order ${job.data.orderId} completed: ${result}`); }); worker.on("failed", (job, err) => { console.log( `Worker: order ${job.data.orderId} failed ` + `(attempt ${job.attemptsMade}/${job.opts.attempts}): ${err.message}` ); }); return worker; } module.exports = { connection, makeQueue, makeWorker, processOrder }; 

Two small scripts send the orders: the first sends order 101 with no worker running, the second sends 102 and 103 once the worker starts, then waits for every result.

// dispatch_first.js: send one order BEFORE any worker is running. const { makeQueue } = require("./queue"); async function main() { const queue = makeQueue(); const job = await queue.add( "process-order", { orderId: 101, customer: "Ayesha", items: ["kurta", "dupatta"], total: 12400 }, { attempts: 3, backoff: { type: "fixed", delay: 1000 } } ); console.log("Sent order 101 for Ayesha (Rs 12400, kurta, dupatta)"); console.log(`Job id: ${job.id}`); console.log(`State right after sending: ${await job.getState()}`); console.log("No worker is running yet, so the order waits in the queue."); require("fs").writeFileSync("first_job_id.txt", String(job.id)); await queue.close(); } main().catch((err) => { console.error(err); process.exit(1); }); 
// dispatch_rest.js: send the rest, then collect every result. const { QueueEvents } = require("bullmq"); const { connection, makeQueue } = require("./queue"); async function main() { const queue = makeQueue(); const events = new QueueEvents("shop-orders", { connection }); const sent = {}; sent[102] = await queue.add( "process-order", { orderId: 102, customer: "Bilal", items: ["sneakers"], total: 7800 }, { attempts: 3, backoff: { type: "fixed", delay: 1000 } } ); console.log("Sent order 102 for Bilal (Rs 7800, sneakers)"); sent[103] = await queue.add( "process-order", { orderId: 103, customer: "Hina", items: ["handbag", "wallet"], total: null }, { attempts: 3, backoff: { type: "fixed", delay: 1000 } } ); console.log("Sent order 103 for Hina (handbag, wallet, NO total)"); console.log("Waiting for results..."); for (const orderId of [101, 102, 103]) { const job = orderId === 101 ? await queue.getJob(require("fs").readFileSync("first_job_id.txt", "utf8").trim()) : sent[orderId]; try { const receipt = await job.waitUntilFinished(events, 30000); console.log(`Order ${orderId}: completed - ${receipt}`); } catch (err) { const state = await job.getState(); console.log(`Order ${orderId}: ${state} - ${err.message}`); } } await events.close(); await queue.close(); } main().catch((err) => { console.error(err); process.exit(1); }); 

Here is the real output. Order 101 was sent with no worker running, so it waited until the worker started and charged it.

$ redis-cli FLUSHALL OK $ node dispatch_first.js Sent order 101 for Ayesha (Rs 12400, kurta, dupatta) Job id: 1 State right after sending: waiting No worker is running yet, so the order waits in the queue. $ node worker.js Worker started, waiting for orders... $ node dispatch_rest.js Sent order 102 for Bilal (Rs 7800, sneakers) Sent order 103 for Hina (handbag, wallet, NO total) Waiting for results... Order 101: completed - Order 101 for Ayesha: charged Rs 12400 for kurta, dupatta; confirmation email queued Order 102: completed - Order 102 for Bilal: charged Rs 7800 for sneakers; confirmation email queued Order 103: failed - order 103 has no total to charge 

The worker log agrees: order 101 completed even though it was sent first, and order 103 failed three times, one second apart, before BullMQ gave up.

Worker started, waiting for orders... Worker: order 101 completed: Order 101 for Ayesha: charged Rs 12400 for kurta, dupatta; confirmation email queued Worker: order 102 completed: Order 102 for Bilal: charged Rs 7800 for sneakers; confirmation email queued Worker: order 103 failed (attempt 1/3): order 103 has no total to charge Worker: order 103 failed (attempt 2/3): order 103 has no total to charge Worker: order 103 failed (attempt 3/3): order 103 has no total to charge 

The thing that went wrong is order 103. With no total, the worker threw, BullMQ retried it twice, and then the job failed for good. A missing total never appears on its own, so retrying it is pointless. Retry only failures that time can fix, and fail fast on bad data. Validate the total before the order reaches the queue, and park failed jobs in a dead-letter queue. The Celery Tutorial: Background Jobs in Python That Just Work post shows the same three orders in Python, and the RabbitMQ Tutorial: An Order Queue That Never Loses Work post shows the dead-letter pattern.

Common mistakes and how to fix them

First, starting the worker before Redis is running. The symptom is a connection refused error, or a worker that crashes on its first job. The fix is to start Redis first and check redis-cli ping prints PONG.

Second, retrying bad data forever. The symptom is a worker log full of retries for a job that can never succeed, like order 103, while good orders wait. The fix is to retry only transient errors, and fail fast on bad data by validating first.

Third, forgetting maxRetriesPerRequest: null with newer ioredis versions. The symptom is a warning that BullMQ requires the option, or jobs that behave oddly under load. The fix is to pass maxRetriesPerRequest: null in the connection options, as the BullMQ docs explain.

Fourth, closing the process before the results arrive. The symptom is a script that sends jobs and exits at once, so waitUntilFinished never resolves. The fix is to stay alive until every job reaches a final state, then close the queue and the events, as dispatch_rest.js does.

Frequently Asked Questions

Do I need Redis to use BullMQ? Yes. BullMQ stores every job in Redis, with no filesystem fallback like the Celery demo used. Local Redis to learn, managed Redis live.

What happens to a job if no worker is running? It waits in Redis. Order 101 stayed waiting until the worker started, then was processed. Nothing was lost.

How is BullMQ different from Celery? They solve the same problem in different languages: Celery is Python with a choice of brokers, BullMQ is Node.js with Redis as its only store. Pick the one your team already runs.

Can I run the worker in the same process as my web server? You can, but you lose the point of the queue: if the server restarts, the worker restarts with it. Run the worker as its own process and keep it alive with PM2 Tutorial: Keep Your Node.js App Running for Good.

What to remember

  • Add slow work with queue.add(), and let the web request answer fast.
  • A job sent with no worker running waits in Redis, it is not lost.
  • Set attempts and backoff per job; retry only failures that time can fix.
  • Make jobs safe to run twice, with an idempotency check.
  • Own Redis: local to learn, managed live.

Where this leaves you

BullMQ earns its place the day a slow step starts breaking web requests that should answer in a blink. The demo proved three things: an order sent before the worker started still got processed, good orders were charged and returned receipts, and the broken order retried twice and then failed loudly instead of vanishing. Start with one queue, one worker, and a local Redis, then move to managed Redis when real users arrive. An empty queue means fast requests, every single time.

Further reading

Waqas Shahid is a software engineer from Karachi with more than 12 years of experience, including 6+ years in engineering leadership. He writes The Practical Developer.