pg-boss vs bull vs agenda vs kue
Background Job Queues for Node.js Applications
pg-bossbullagendakueSimilar Packages:

Background Job Queues for Node.js Applications

agenda, bull, kue, and pg-boss are Node.js libraries designed to manage background tasks and scheduled jobs. They allow developers to offload time-consuming work β€” such as sending emails, processing images, or generating reports β€” from the main application thread. Each library uses a different storage backend: agenda relies on MongoDB, bull and kue use Redis, and pg-boss leverages PostgreSQL. These tools help ensure tasks are not lost during crashes and can be retried if they fail.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
pg-boss2,069,8374,0841.35 MB1411 days agoMIT
bull1,020,64616,257309 kB1482 years agoMIT
agenda91,3019,710301 kB453 months agoMIT
kue13,5809,417-2869 years agoMIT

Background Job Queues: Agenda vs Bull vs Kue vs pg-boss

When building Node.js applications, you often need to handle tasks that take too long to run during a standard HTTP request. Sending emails, resizing images, or syncing data are common examples. The agenda, bull, kue, and pg-boss packages solve this by moving work to background jobs. They ensure tasks are saved safely and processed reliably, even if the server restarts. Let's compare how they handle storage, job definition, scheduling, and error management.

πŸ’Ύ Storage Engine: MongoDB vs Redis vs PostgreSQL

The core difference lies in where job data is stored. This affects your infrastructure choices and performance.

agenda stores jobs directly in MongoDB collections.

  • Uses standard database documents for job state.
  • Good if you already use Mongo for app data.
// agenda: MongoDB connection
const agenda = new Agenda({ db: { address: 'mongodb://localhost/agenda' } });
await agenda.start();

bull stores jobs in Redis using lists and hashes.

  • Very fast read/write operations.
  • Requires a separate Redis server instance.
// bull: Redis connection
const Queue = require('bull');
const queue = new Queue('email-queue', 'redis://localhost:6379');

kue also stores jobs in Redis.

  • Similar to bull but uses an older data structure approach.
  • Requires a separate Redis server instance.
// kue: Redis connection
const kue = require('kue');
const queue = kue.createQueue({ redis: { port: 6379, host: 'localhost' } });

pg-boss stores jobs in PostgreSQL tables.

  • Uses standard SQL tables and LISTEN/NOTIFY.
  • No new database engine needed if you use Postgres.
// pg-boss: PostgreSQL connection
const Boss = require('pg-boss');
const boss = new Boss({ connectionString: 'postgres://user:pass@localhost/db' });
await boss.start();

πŸ“ Defining and Processing Jobs

Each library has a different way to register the function that actually does the work.

agenda uses define to register a handler.

  • The handler receives a job object with data.
  • Uses async/await or callbacks.
// agenda: Define job handler
agenda.define('send-email', async (job) => {
  const { to, subject } = job.attrs.data;
  await sendMail(to, subject);
});

bull uses process to register a worker.

  • The worker function receives the job data directly.
  • Supports concurrency limits.
// bull: Process job
queue.process(async (job) => {
  const { to, subject } = job.data;
  await sendMail(to, subject);
});

kue uses process with a callback style.

  • Requires calling done() to signal completion.
  • Older pattern compared to modern promises.
// kue: Process job
queue.process('send-email', async (job, done) => {
  try {
    await sendMail(job.data.to, job.data.subject);
    done();
  } catch (err) {
    done(err);
  }
});

pg-boss uses work to register a handler.

  • Similar to agenda but with Postgres backend.
  • Returns a promise to signal completion.
// pg-boss: Work on job
await boss.work('send-email', async (job) => {
  const { to, subject } = job.data;
  await sendMail(to, subject);
});

πŸ•’ Scheduling and Immediate Execution

Some tasks need to run right away, while others need to wait for a specific time.

agenda supports now for immediate jobs and schedule for future jobs.

  • Very flexible cron syntax for recurring tasks.
// agenda: Schedule job
await agenda.now('send-email', { to: '[email protected]' });
await agenda.schedule('in 1 hour', 'send-email', { to: '[email protected]' });

bull uses add with options for delays.

  • Supports delayed jobs via Redis timestamps.
  • Recurring jobs require plugins or external schedulers.
// bull: Add delayed job
await queue.add({ to: '[email protected]' }, { delay: 3600000 });

kue uses delay on the job instance.

  • Simple delay mechanism.
  • Less robust recurring job support.
// kue: Delay job
const job = queue.create('send-email', { to: '[email protected]' });
job.delay(3600000).save();

pg-boss uses send with a startAfter option.

  • Uses database timestamps for scheduling.
  • Supports cron-like scheduling via configuration.
// pg-boss: Send scheduled job
await boss.send('send-email', { to: '[email protected]' }, { startAfter: '1 hour' });

⚠️ Error Handling and Retries

Jobs fail. Networks drop. Databases lock. Your queue must handle these issues.

agenda retries based on configuration.

  • Failed jobs remain in the database for inspection.
  • You must manually handle failure logic in the define block.
// agenda: Error handling
agenda.define('send-email', async (job) => {
  try {
    await sendMail();
  } catch (err) {
    // Log error, job remains failed in DB
    console.error(err);
  }
});

bull has built-in retry attempts.

  • Configure attempts and backoff strategies easily.
  • Moves failed jobs to a special failed list.
// bull: Retry configuration
queue.process(async (job) => {
  await sendMail();
}, { attempts: 3, backoff: { type: 'exponential', delay: 1000 } });

kue handles retries via attempts.

  • Similar to bull but less configurable.
  • Failed jobs stay in the queue UI for review.
// kue: Retry configuration
const job = queue.create('send-email', data);
job.attempts(3).save();

pg-boss manages retries internally.

  • Expired or failed jobs can be archived or retried.
  • Uses database transactions for safety.
// pg-boss: Retry configuration
await boss.work('send-email', { retryLimit: 3 }, async (job) => {
  await sendMail();
});

πŸ›‘ Maintenance Status and Risks

Choosing a library means trusting its future support.

agenda is actively maintained.

  • Regular updates and security patches.
  • Safe for long-term projects.

bull is in maintenance mode.

  • Still stable, but bullmq is the recommended modern version.
  • Safe for existing projects, consider bullmq for new ones.

kue is deprecated and abandoned.

  • Do not use for new projects.
  • Known security issues and no fixes.

pg-boss is actively maintained.

  • Growing popularity among Postgres users.
  • Safe for long-term projects.

πŸ“Š Summary: Key Differences

Featureagendabullkuepg-boss
BackendπŸƒ MongoDBπŸ“ RedisπŸ“ Redis🐘 PostgreSQL
Statusβœ… Active⚠️ Maintenance❌ Deprecatedβœ… Active
SchedulingπŸ•’ Built-in Cron⏱️ Delay Only⏱️ Delay OnlyπŸ•’ Built-in Cron
API StyleπŸ“˜ Define/NowπŸ“˜ Add/ProcessπŸ“˜ Create/ProcessπŸ“˜ Publish/Work
InfrastructureπŸ—„οΈ Requires MongoπŸ—„οΈ Requires RedisπŸ—„οΈ Requires RedisπŸ—„οΈ Requires Postgres

πŸ’‘ Final Recommendation

agenda is the best choice if you already run MongoDB and need complex scheduling without adding new tools. It balances features and simplicity well.

bull remains a solid option for high-performance needs with Redis, but consider its successor bullmq for new development. It handles high concurrency better than most.

kue should be avoided entirely. It is outdated and poses security risks. Migrate existing systems to bull or pg-boss.

pg-boss is the top pick for PostgreSQL shops. It reduces infrastructure complexity by keeping jobs in your main database. It is modern, safe, and easy to adopt.

Final Thought: All four libraries solve the same problem β€” keeping background work reliable. Your choice should depend on your existing database stack and whether you need advanced scheduling features.

How to Choose: pg-boss vs bull vs agenda vs kue

  • pg-boss:

    Choose pg-boss if your stack is centered on PostgreSQL and you want to avoid managing separate Redis or MongoDB instances. It uses standard database features like LISTEN/NOTIFY to handle job distribution efficiently. This is ideal for teams seeking to simplify infrastructure by consolidating data storage.

  • bull:

    Choose bull if you need high-performance job processing and already use Redis for caching or sessions. It is a mature solution with strong community support, though note that bullmq is the newer successor for modern projects. This package excels in scenarios requiring priority queues and high concurrency.

  • agenda:

    Choose agenda if your infrastructure already relies on MongoDB and you need robust cron-like scheduling features. It is well-suited for applications that require complex job recurrence rules without adding new database dependencies. However, be aware that heavy write loads on the job collection can impact database performance.

  • kue:

    Do not choose kue for new projects as it is deprecated and no longer maintained. While it pioneered Redis-based queues in Node.js, security vulnerabilities and lack of updates make it risky. Evaluate bull or pg-boss instead for similar functionality with active support.

README for pg-boss

Queueing jobs in Postgres from Node.js like a boss.

Build Coverage NPM

async function readme() {
  const { PgBoss } = require('pg-boss');
  const boss = new PgBoss('postgres://user:pass@host/database');

  boss.on('error', console.error)

  await boss.start()

  const queue = 'readme-queue'

  await boss.createQueue(queue)

  const id = await boss.send(queue, { arg1: 'read me' })

  console.log(`created job ${id} in queue ${queue}`)

  await boss.work(queue, async ([ job ]) => {
    console.log(`received job ${job.id} with data ${JSON.stringify(job.data)}`)
  })
}

readme()
  .catch(err => {
    console.log(err)
    process.exit(1)
  })

pg-boss is a job queue built in Node.js on top of PostgreSQL in order to provide background processing and reliable asynchronous execution to Node.js applications.

pg-boss relies on Postgres's SKIP LOCKED, a feature built specifically for message queues to resolve record locking challenges inherent with relational databases. Concurrent workers claim jobs without blocking each other, and job processing gets the safety of guaranteed atomic commits.

This will likely cater the most to teams already familiar with the simplicity of relational database semantics and operations (SQL, querying, and backups). It will be especially useful to those already relying on PostgreSQL that want to limit how many systems are required to monitor and support in their architecture.

Summary

  • Create jobs in an existing db transaction, including adapters for popular ORMs such as Drizzle, Knex, Kysely, Prisma
  • Backpressure-compatible polling workers, including support for LISTEN/NOTIFY low latency delivery
  • Job dependency workflow orchestration
  • Cron and RRULE scheduling, job deferral
  • Queue storage policies to support a variety of rate limiting, debouncing, and concurrency use cases
  • Priority queues, dead letter queues with redrive, automatic retries with exponential backoff
  • Pub/sub API for fan-out queue relationships
  • SQL support for non-Node.js runtimes for most operations
  • Serverless function compatible
  • OpenTelemetry traces and metrics
  • Multi-master compatible (for example, in a Kubernetes ReplicaSet)
  • Additional database backends for Postgres-based databases such as CockroachDB and Citus. Or, use embedded PGlite for running entirely in-process.

CLI

pg-boss includes a command-line interface if needed for managing database migrations without writing code. This is useful for CI/CD pipelines, database setup scripts, or manual schema management.

See the CLI documentation for details.

Dashboard

A web-based dashboard is available in the @pg-boss/dashboard package for monitoring and managing jobs, queues and schedules.

See the dashboard documentation for details.

Proxy

A HTTP proxy is available in the @pg-boss/proxy package if needed to support use cases such as platform compatibility and connection pooling or scalability.

See the proxy documentation for details.

Requirements

  • Node 22.12 or higher, or Bun
  • PostgreSQL 13 or higher

Sponsors

pg-boss is MIT licensed and always will be. It is maintained by one person, and sponsorship is what pays for the maintenance, security response, and support behind it.

Become a sponsor, or see everyone who already does on the sponsors page.

Superpower Altruistiq wasp-lang Ferry Health

Documentation

Contributing

To setup a development environment for this library:

git clone https://github.com/timgit/pg-boss.git
npm install

To run the test suite, linter and code coverage:

npm run cover

The test suite will try and create a new database named pgboss. The config.json file has the default credentials to connect to postgres.

The Docker Compose file can be used to start a local postgres instance for testing:

docker compose up