Module P-12·23 min read

Why job queues exist, BullMQ with Redis, workers and concurrency, retries and exponential backoff, dead letter queues, cron jobs, and real-world use cases.

JJS
Written by Jatin Jain Saraf · Senior Software Engineer

Module P-12 — Background Jobs and Task Queues with BullMQ

What this module covers: Some work is too slow, too unreliable, or too risky to do inside a request. Sending email, resizing images, calling third-party APIs, generating reports, sending push notifications — all of these should happen off the request path. This module covers why job queues exist, BullMQ's architecture with Redis, defining and dispatching jobs, writing workers with concurrency control, retries with exponential backoff, dead letter queues for failed jobs, repeatable cron jobs, and the patterns that make queues reliable in production.


Why Job Queues

A job queue is a restaurant's order rail — the waiter can hand off a ticket the instant it's written and get back to the floor, while the kitchen fires it at its own pace.

Consider sending a transactional email when an order is placed. Three approaches:

typescript

A job queue gives you:

  • Decoupled execution — the response returns before the work is done
  • Automatic retries — if the email provider is down, the job retries with backoff
  • Visibility — you can see queued, active, completed, and failed jobs
  • Rate limiting — process at most N jobs per second regardless of how many are enqueued
  • Concurrency control — run M workers in parallel without overloading the system
  • Persistence — jobs survive process restarts (stored in Redis)

BullMQ Architecture

BullMQ uses Redis as its store. Three components:

text

The queue lives in Redis — producers and workers are just Node.js processes that connect to it. You can have multiple producers (different API instances) and multiple workers (separate scaling).

bash

Defining Queues and Adding Jobs

typescript

Adding jobs from your service:

typescript

Job options per-add

typescript

Writing Workers

A worker subscribes to a queue and processes jobs:

typescript

Sign in to keep reading

The rest of this module is free — sign in with Google to unlock it and track your progress.

Sign in & Register

Discussion

0

Join the discussion

Loading comments...

© 2026 Jatin Jain Saraf (JJS). All rights reserved.