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.
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.
The core difference lies in where job data is stored. This affects your infrastructure choices and performance.
agenda stores jobs directly in MongoDB collections.
// agenda: MongoDB connection
const agenda = new Agenda({ db: { address: 'mongodb://localhost/agenda' } });
await agenda.start();
bull stores jobs in Redis using lists and hashes.
// bull: Redis connection
const Queue = require('bull');
const queue = new Queue('email-queue', 'redis://localhost:6379');
kue also stores jobs in Redis.
bull but uses an older data structure approach.// kue: Redis connection
const kue = require('kue');
const queue = kue.createQueue({ redis: { port: 6379, host: 'localhost' } });
pg-boss stores jobs in PostgreSQL tables.
LISTEN/NOTIFY.// pg-boss: PostgreSQL connection
const Boss = require('pg-boss');
const boss = new Boss({ connectionString: 'postgres://user:pass@localhost/db' });
await boss.start();
Each library has a different way to register the function that actually does the work.
agenda uses define to register a handler.
// 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.
// bull: Process job
queue.process(async (job) => {
const { to, subject } = job.data;
await sendMail(to, subject);
});
kue uses process with a callback style.
done() to signal completion.// 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.
agenda but with Postgres backend.// pg-boss: Work on job
await boss.work('send-email', async (job) => {
const { to, subject } = job.data;
await sendMail(to, subject);
});
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.
// 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.
// bull: Add delayed job
await queue.add({ to: '[email protected]' }, { delay: 3600000 });
kue uses delay on the job instance.
// kue: Delay job
const job = queue.create('send-email', { to: '[email protected]' });
job.delay(3600000).save();
pg-boss uses send with a startAfter option.
// pg-boss: Send scheduled job
await boss.send('send-email', { to: '[email protected]' }, { startAfter: '1 hour' });
Jobs fail. Networks drop. Databases lock. Your queue must handle these issues.
agenda retries based on configuration.
// 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.
// bull: Retry configuration
queue.process(async (job) => {
await sendMail();
}, { attempts: 3, backoff: { type: 'exponential', delay: 1000 } });
kue handles retries via attempts.
bull but less configurable.// kue: Retry configuration
const job = queue.create('send-email', data);
job.attempts(3).save();
pg-boss manages retries internally.
// pg-boss: Retry configuration
await boss.work('send-email', { retryLimit: 3 }, async (job) => {
await sendMail();
});
Choosing a library means trusting its future support.
agenda is actively maintained.
bull is in maintenance mode.
bullmq is the recommended modern version.bullmq for new ones.kue is deprecated and abandoned.
pg-boss is actively maintained.
| Feature | agenda | bull | kue | pg-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 |
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.
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.
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.
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.
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.
Queueing jobs in Postgres from Node.js like a boss.
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.
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.
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.
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.
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.
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