The Complete Guide to BullMQ with Arctickey
Job queues are the unsung heroes of modern web applications. They handle everything from sending emails to processing payments to generating reports—all without making your users wait.
BullMQ is the most popular job queue for Node.js, and for good reason. It's battle-tested, feature-rich, and powered by Redis. In this guide, we'll go from zero to production-ready.
Why BullMQ?
I've tried many queue systems over the years. BullMQ stands out because:
- It just works — No message loss, proper error handling out of the box
- It scales — Run as many workers as you need across multiple servers
- It's observable — Built-in support for monitoring and metrics
Setting Up
First, install BullMQ:
npm install bullmqCreate a queue and add your first job:
import { Queue } from 'bullmq'
const emailQueue = new Queue('emails', {
connection: {
host: 'eu.arctickey.com',
password: process.env.REDIS_PASSWORD
}
})
await emailQueue.add('welcome', {
to: 'user@example.com'
})Processing Jobs
Create a worker to process the jobs:
import { Worker } from 'bullmq'
const worker = new Worker('emails', async (job) => {
await sendEmail(job.data)
console.log(`Sent email to ${job.data.to}`)
}, { connection })
worker.on('failed', (job, err) => {
console.error(`Job failed: ${err.message}`)
})Scaling tip
Job Options That Matter
The real power of BullMQ comes from its job options:
await queue.add('important-job', data, {
priority: 1, // Process first
attempts: 3, // Retry on failure
delay: 5000, // Wait 5s before processing
backoff: {
type: 'exponential',
delay: 1000
}
})Production Best Practices
After running BullMQ in production for years, here's what I've learned:
- Always set maxStalledCount — Prevents zombie jobs from blocking your queue
- Use removeOnComplete — Keep your Redis memory under control
- Monitor with Bull Board — Visual dashboard for your queues
- Separate queues by priority — Critical jobs shouldn't wait behind bulk operations
BullMQ is one of those tools that becomes invisible when it's working well—which is exactly what you want from your infrastructure.
Ready to build something amazing?
Get your Redis database running in 30 seconds. No credit card required.
Start Free →