Skip to content

Rate Limiting & Concurrency Control for Bun Job Queues

Control the rate at which jobs are processed.

Limit jobs per time window:

Terminal window
# CLI
bunqueue rate-limit set emails 100 # 100 jobs/second
bunqueue rate-limit clear emails

Limit concurrent active jobs:

Terminal window
# CLI
bunqueue concurrency set emails 5 # Max 5 concurrent
bunqueue concurrency clear emails

In embedded mode you can call queue.setGlobalRateLimit(max, duration?) / queue.setGlobalConcurrency(n) directly, use a per-worker limiter, or control throughput with worker concurrency:

const queue = new Queue('emails', { embedded: true });
// Control processing rate with worker concurrency
const worker = new Worker('emails', processor, {
embedded: true,
concurrency: 5, // Max 5 parallel jobs
});

For custom time-based rate limiting beyond the built-in options, you can also implement it in your processor:

import { Ratelimit } from '@upstash/ratelimit'; // or similar
const ratelimit = new Ratelimit({ ... });
const worker = new Worker('emails', async (job) => {
await ratelimit.limit('email-send'); // External rate limiter
await sendEmail(job.data);
}, { embedded: true });