Skip to main content
BullMQ provides queue rate limiting capabilities to control how many jobs are processed within a given time period. This is useful for respecting external API limits, protecting downstream services, or managing resource consumption.

Worker-Level Rate Limiting

Configure rate limiting directly on your worker instances:
limiter.max
number
required
Maximum number of jobs to process within the duration period
limiter.duration
number
required
Time window in milliseconds for the rate limit
The rate limiter is global across all workers for the same queue. If you have 10 workers with the settings above, only 10 jobs total will be processed per second across all workers.
Jobs that get rate limited will stay in the waiting state until the rate limit window resets.

Queue-Level Rate Limiting

You can also set rate limits at the queue level using the setGlobalRateLimit method:
See Global Rate Limit for more details on queue-level rate limiting.

Manual Rate Limiting

Sometimes you need dynamic rate limiting based on runtime conditions, such as receiving a 429 Too Many Requests response from an API:
You must include limiter options in your worker configuration for manual rate limiting to work. The limiter.max value determines if rate limit validation is executed.
When using manual rate limiting, you must throw Worker.RateLimitError() to differentiate rate limiting from actual job failures. This ensures the job returns to the waiting state instead of being marked as failed.

Checking Rate Limit Status

Get Rate Limit TTL

Check if your queue is currently rate limited and when it will reset:

Remove Rate Limit

Manually clear the rate limit to allow immediate job processing:
Removing the rate limit key resets the counter to zero, allowing workers to immediately begin processing jobs again.

Practical Examples

Example 1: External API Rate Limits

Many third-party APIs enforce rate limits:

Example 2: Email Service Limits

Example 3: Burst Protection

Rate Limiting vs Concurrency

Rate limiting controls how many jobs are processed over a time period:
Concurrency controls how many jobs run simultaneously:
These work together:
See Concurrency and Global Concurrency for more details.

Monitoring Rate Limits

Track rate limit behavior in your application:

Best Practices

1

Match external rate limits

Configure your rate limits to match or be slightly lower than external API limits to avoid 429 errors.
2

Use manual rate limiting for dynamic limits

When APIs return rate limit headers, use manual rate limiting to respect them dynamically.
3

Monitor rate limit status

Regularly check getRateLimitTtl() to understand if your queue is being throttled.
4

Combine with retry strategies

Use rate limiting alongside retry strategies for robust error handling.
5

Consider multiple queues

For different rate limit requirements, use separate queues with different limits.

Global Rate Limit

Queue-level rate limiting across all workers

Concurrency

Control parallel job processing

Global Concurrency

Limit concurrent jobs across all workers

Retrying Failing Jobs

Handle job failures with retries

API Reference