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

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 long-running or resource-intensive operations asynchronously, without blocking the main request processing thread. Typical examples include: sending email notifications, processing uploaded images, generating PDF reports, or synchronizing with external APIs. To solve these problems, job queues are used — a mechanism that allows you to defer work execution, distribute load, and ensure fault tolerance.



In this article, we will look at three popular libraries for queue management in the Node.js ecosystem: Bull, Bee-Queue, and Kue. Each of them has its own features, advantages, and use cases.



Why are task queues needed?



The main reasons for implementing queues in a Node.js backend:

  • Offloading the main thread. Long operations (e.g., sending 1000 emails) do not block the user response.
  • Retries. If a job fails with an error, the queue automatically retries it after a specified interval.
  • Scheduling. You can delay job execution for a specific time (e.g., after 1 hour).
  • Scalability. Multiple workers can process jobs from a single queue in parallel.


1. Bull — Modern and Performant Queue



Bull is one of the most popular libraries for working with queues in Node.js. It is built on top of Redis and provides a rich API for job management.



Key features of Bull:

  • Support for job priorities.
  • Configurable retries.
  • Delayed job execution (delay).
  • Events (job completed, error, progress).
  • Built-in UI interface for monitoring via bull-board.


Installation:

npm install bull


Example of creating a queue and a processor:

const Queue = require('bull');

// Create a queue for sending emailsconst emailQueue = new Queue('email', { redis: { host: '127.0.0.1', port: 6379 }});

// Add a job to the queueemailQueue.add({ to: 'user@example.com', subject: 'Hello!', body: 'This is a test email'}, { attempts: 3, // retry up to 3 times on error delay: 5000 // delay by 5 seconds});

// Job processoremailQueue.process(async (job) => { const { to, subject, body } = job.data; // Simulate sending an email await sendEmail(to, subject, body); console.log(`Email sent: ${to}`);});


When to choose Bull: if you need a reliable queue with advanced features (priorities, retries, monitoring) and you are ready to use Redis.



2. Bee-Queue — Lightweight and Fast



Bee-Queue is a minimalist queue, also running on Redis. It is focused on simplicity and performance. The library code is compact, and the API is intuitive.



Features of Bee-Queue:

  • No dependencies other than Redis.
  • Support for events (ready, job succeeded, job failed).
  • Ability to configure a processing timeout.
  • Simple retry system.


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 }});

// Add a jobimageQueue.createJob({ imagePath: '/uploads/photo.jpg' }) .retries(2) .save();

// ProcessorimageQueue.process(async (job) => { const {

Recommendations