BullMQ — Redis-Based Job Queue for Node.js
You are an expert in BullMQ, the high-performance job queue for Node.js built on Redis. You help developers build reliable background processing systems with delayed jobs, rate limiting, prioritization, repeatable cron jobs, job dependencies, concurrency control, and dead-letter handling — powering email sending, image processing, webhook delivery, report generation, and any async workload.
Core Capabilities
Queue and Worker
import { Queue, Worker, QueueScheduler, FlowProducer } from "bullmq";
import IORedis from "ioredis";
const connection = new IORedis({ host: "localhost", port: 6379, maxRetriesPerRequest: null });
// Define queue
const emailQueue = new Queue("email", { connection });
// Add jobs
await emailQueue.add("welcome", {
to: "user@example.com",
template: "welcome",
data: { name: "Alice" },
}, {
priority: 1, // Lower = higher priority
attempts: 3, // Retry up to 3 times
backoff: { type: "exponential", delay: 2000 },
removeOnComplete: { count: 1000 }, // Keep last 1000 completed
removeOnFail: { age: 7 * 24 * 3600 }, // Keep failed for 7 days
});
// Delayed job
await emailQueue.add("reminder", { userId: 42 }, {
delay: 24 * 60 * 60 * 1000, // 24 hours from now
});
// Repeatable (cron)
await emailQueue.add("digest", {}, {
repeat: { pattern: "0 9 * * 1" }, // Every Monday at 9 AM
});
// Worker
const worker = new Worker("email", async (job) => {
switch (job.name) {
case "welcome":
await sendEmail(job.data.to, job.data.template, job.data.data);
break;
case "reminder":
await sendReminderEmail(job.data.userId);
break;
case "digest":
await sendWeeklyDigest();
break;
}
// Progress reporting
await job.updateProgress(100);
return { sent: true, timestamp: Date.now() };
}, {
connection,
concurrency: 5, // Process 5 jobs simultaneously
limiter: { max: 100, duration: 60000 }, // Rate limit: 100 jobs/min
});
worker.on("completed", (job, result) => console.log(`Job ${job.id} completed`));
worker.on("failed", (job, err) => console.error(`Job ${job?.id} failed: ${err.message}`));
Job Flows (Parent-Child Dependencies)
const flow = new FlowProducer({ connection });
await flow.add({
name: "generate-report",
queueName: "reports",
data: { reportId: "monthly-2026-03" },
children: [
{ name: "fetch-sales", queueName: "data", data: { source: "sales" } },
{ name: "fetch-users", queueName: "data", data: { source: "users" } },
{ name: "fetch-metrics", queueName: "data", data: { source: "metrics" } },
],
// Parent job runs only after ALL children complete
});
Installation
npm install bullmq ioredis
Best Practices
- Separate workers — Run workers in separate processes/containers from your API; scale independently
- Idempotent jobs — Design jobs to be safely retried; use unique job IDs to prevent duplicates
- Backoff strategy — Use exponential backoff for retries; prevents thundering herd on downstream failures
- Rate limiting — Use
limiter to respect API rate limits (email providers, webhooks, external APIs)
- Progress tracking — Use
job.updateProgress() for long-running jobs; clients can poll progress
- Graceful shutdown — Call
worker.close() on SIGTERM; finishes current jobs before exiting
- Flows for pipelines — Use FlowProducer for job dependencies; parent waits for all children to complete
- Monitor with Bull Board — Use
@bull-board/express for a web UI showing queue status, job data, and failures
1---2name: bull-mq3description: >-4 You are an expert in BullMQ, the high-performance job queue for Node.js5 built on Redis. You help developers build reliable background processing6 systems with delayed jobs, rate limiting, prioritization, repeatable cron7 jobs, job dependencies, concurrency control, and dead-letter handling —8 powering email sending, image processing, webhook delivery, report9 generation, and any async workload.10license: Apache-2.011compatibility: ''12metadata:13 source: https://skillmd.com/skills/eliferjunior/bull-mq14 author: terminal-skills15 version: 1.0.016 category: Backend Development17 tags:18 - queue19 - redis20 - jobs21 - background22 - worker23 - cron24 - node25---2627# BullMQ — Redis-Based Job Queue for Node.js2829You are an expert in BullMQ, the high-performance job queue for Node.js built on Redis. You help developers build reliable background processing systems with delayed jobs, rate limiting, prioritization, repeatable cron jobs, job dependencies, concurrency control, and dead-letter handling — powering email sending, image processing, webhook delivery, report generation, and any async workload.3031## Core Capabilities3233### Queue and Worker3435```typescript36import { Queue, Worker, QueueScheduler, FlowProducer } from "bullmq";37import IORedis from "ioredis";3839const connection = new IORedis({ host: "localhost", port: 6379, maxRetriesPerRequest: null });4041// Define queue42const emailQueue = new Queue("email", { connection });4344// Add jobs45await emailQueue.add("welcome", {46 to: "user@example.com",47 template: "welcome",48 data: { name: "Alice" },49}, {50 priority: 1, // Lower = higher priority51 attempts: 3, // Retry up to 3 times52 backoff: { type: "exponential", delay: 2000 },53 removeOnComplete: { count: 1000 }, // Keep last 1000 completed54 removeOnFail: { age: 7 * 24 * 3600 }, // Keep failed for 7 days55});5657// Delayed job58await emailQueue.add("reminder", { userId: 42 }, {59 delay: 24 * 60 * 60 * 1000, // 24 hours from now60});6162// Repeatable (cron)63await emailQueue.add("digest", {}, {64 repeat: { pattern: "0 9 * * 1" }, // Every Monday at 9 AM65});6667// Worker68const worker = new Worker("email", async (job) => {69 switch (job.name) {70 case "welcome":71 await sendEmail(job.data.to, job.data.template, job.data.data);72 break;73 case "reminder":74 await sendReminderEmail(job.data.userId);75 break;76 case "digest":77 await sendWeeklyDigest();78 break;79 }8081 // Progress reporting82 await job.updateProgress(100);83 return { sent: true, timestamp: Date.now() };84}, {85 connection,86 concurrency: 5, // Process 5 jobs simultaneously87 limiter: { max: 100, duration: 60000 }, // Rate limit: 100 jobs/min88});8990worker.on("completed", (job, result) => console.log(`Job ${job.id} completed`));91worker.on("failed", (job, err) => console.error(`Job ${job?.id} failed: ${err.message}`));92```9394### Job Flows (Parent-Child Dependencies)9596```typescript97const flow = new FlowProducer({ connection });9899await flow.add({100 name: "generate-report",101 queueName: "reports",102 data: { reportId: "monthly-2026-03" },103 children: [104 { name: "fetch-sales", queueName: "data", data: { source: "sales" } },105 { name: "fetch-users", queueName: "data", data: { source: "users" } },106 { name: "fetch-metrics", queueName: "data", data: { source: "metrics" } },107 ],108 // Parent job runs only after ALL children complete109});110```111112## Installation113114```bash115npm install bullmq ioredis116```117118## Best Practices1191201. **Separate workers** — Run workers in separate processes/containers from your API; scale independently1212. **Idempotent jobs** — Design jobs to be safely retried; use unique job IDs to prevent duplicates1223. **Backoff strategy** — Use exponential backoff for retries; prevents thundering herd on downstream failures1234. **Rate limiting** — Use `limiter` to respect API rate limits (email providers, webhooks, external APIs)1245. **Progress tracking** — Use `job.updateProgress()` for long-running jobs; clients can poll progress1256. **Graceful shutdown** — Call `worker.close()` on SIGTERM; finishes current jobs before exiting1267. **Flows for pipelines** — Use FlowProducer for job dependencies; parent waits for all children to complete1278. **Monitor with Bull Board** — Use `@bull-board/express` for a web UI showing queue status, job data, and failures