Task Queues in Node.js: Bull, Bee-Queue, Kue and Redis Implementation

Online Python Trainer for Beginners

Learn Python easily without overwhelming theory. Solve practical tasks with automatic checking, get hints in Russian, and write code directly in your browser — no installation required.

Start Course

Task Queues for JavaScript (Node.js): Bull, Bee-Queue and Kue



When developing web applications in Node.js, there is often a need to perform resource-intensive or long-running operations outside the main HTTP request processing thread. Sending email newsletters, generating PDF reports, processing uploaded images, or interacting with external APIs — all these tasks can block the user response if executed synchronously. To solve this problem, job queues are used.



A job queue is a mechanism that allows you to:

  • Defer work to be done in the background.
  • Manage priorities and the order of processing.
  • Automatically retry jobs on errors.
  • Scale processing horizontally (multiple workers).


In the Node.js ecosystem, three libraries have gained the most popularity: Bull, Bee-Queue, and Kue. They are all built on top of Redis, which ensures high performance and fault tolerance. Let's look at each of them in detail.






1. Bull — The Most Popular and Feature-Rich Queue



Bull (npm: bull) is a mature, well-documented library that supports almost all necessary scenarios: delayed jobs, scheduled repetition, priorities, rate limits, error stacks, and even a visual interface (Arete). Bull is actively maintained by the community and is recommended for production projects.



Installation:

npm install bull


A simple example — creating a queue and a handler:



const Queue = require('bull');

// Create a queue named 'email'const emailQueue = new Queue('email', { redis: { host: 'localhost', port: 6379 }});

// Add a jobemailQueue.add({ to: 'user@example.com', subject: 'Welcome!', body: 'Thank you for registering.'}, { attempts: 3, // retries on error backoff: 5000, // delay between retries (5 sec) delay: 10000 // delay by 10 seconds});

// Handler (worker)emailQueue.process(async (job) => { const { to, subject, body } = job.data; console.log(`Sending email to ${to}: ${subject}`); // Here call your email sending function await sendEmail(to, subject, body);});


Key features of Bull:

  • Retries — configure the number of retries and exponential backoff.
  • Scheduling (cron) — execute jobs on a schedule (e.g., every night).
  • Priorities — high-priority jobs are processed first.
  • Events — subscribe to events (completed, failed, progress).
  • Graceful shutdown — proper shutdown handling.





2. Bee-Queue — Lightweight and Fast Queue



Bee-Queue (npm: bee-queue) is a minimalistic alternative to Bull. It offers only basic features but does so with minimal overhead. Bee-Queue is ideal for simple scenarios where complex configuration is not needed, but speed is important.



Installation:

npm install bee-queue


Usage example:



const Queue = require('bee-queue');

const imageQueue = new Queue('image-processing', { redis: { host: '127.0.0.1', port: 6379 }, isWorker: true});

// Add a jobimageQueue.createJob({ imageId: 123, size: 'thumbnail' }) .timeout(30000) // timeout 30 sec .retries(2) // 2 retries .save() .then(job => console.log('Job created:', job.id));

// HandlerimageQueue.process((job, done) => { console.log(`Processing image ${job.data.imageId}`); // Do the work proce

Recommendations