Rate Limiting & Concurrency Control for Bun Job Queues
Control the rate at which jobs are processed.
Rate Limit
Section titled “Rate Limit”Limit jobs per time window:
# CLIbunqueue rate-limit set emails 100 # 100 jobs/secondbunqueue rate-limit clear emailsConcurrency Limit
Section titled “Concurrency Limit”Limit concurrent active jobs:
# CLIbunqueue concurrency set emails 5 # Max 5 concurrentbunqueue concurrency clear emailsEmbedded Mode
Section titled “Embedded Mode”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 concurrencyconst 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 });