Worker-Level Rate Limiting
Configure rate limiting directly on your worker instances:Maximum number of jobs to process within the duration period
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.
Queue-Level Rate Limiting
You can also set rate limits at the queue level using thesetGlobalRateLimit method:
Manual Rate Limiting
Sometimes you need dynamic rate limiting based on runtime conditions, such as receiving a429 Too Many Requests response from an API:
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: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.
Related Topics
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
