Skip to main content
Global rate limiting is a queue-level setting that determines the maximum number of jobs that can be processed within a specific time period across all worker instances.

Setting Global Rate Limit

Use the setGlobalRateLimit method to configure rate limiting:

Method Signature

max
number
required
Maximum number of jobs to process in the time period specified by duration
duration
number
required
Time period in milliseconds. During this time, a maximum of max jobs will be processed.

Example

Getting Global Rate Limit

Retrieve the current rate limit configuration:

Getting Rate Limit TTL

Check how much time remains until the rate limit window resets:

Removing Global Rate Limit

Remove the rate limit, allowing unlimited job processing:

How It Works

Global vs Worker Rate Limits

BullMQ supports rate limiting at both the worker and queue level: Worker-level rate limit (per worker instance):
Global rate limit (across all workers):
Worker-level rate limits do not override the global rate limit. The global limit is always enforced across all workers.

Practical Examples

Example 1: External API Rate Limits

Many APIs enforce rate limits. Use global rate limiting to respect them:

Example 2: Email Service Rate Limits

Example 3: Database Rate Limiting

Protect your database from overload:

Example 4: Burst Protection

Handle traffic spikes gracefully:

Temporary Rate Limit Override

You can temporarily override the rate limit using the rateLimit method:
The rateLimit method sets a temporary override that expires after the specified time.

Combining Rate Limit and Concurrency

You can use both global concurrency and rate limiting together:

Dynamic Rate Limiting

Adjust rate limits based on external factors:

Monitoring Rate Limits

Check the current rate limit status:

Use Cases

When to Use Global Rate Limiting

  • External API rate limits (GitHub, Stripe, SendGrid, etc.)
  • Database query quotas
  • Third-party service limits
  • Cost control (pay-per-request services)
  • Infrastructure protection
  • Compliance requirements

When NOT to Use Global Rate Limiting

  • Jobs are completely independent
  • You want maximum throughput
  • No external rate limits exist
  • Cost is not a concern

Common Patterns

Pattern 1: Tiered Rate Limits

Pattern 2: Time-of-Day Rate Limits