Skip to main content

Overview

Throw RateLimitError from a job processor to indicate that the job should be retried later due to rate limiting.

Class

Creating Rate Limit Errors

Use the static method on the Worker class:
Or import the class directly:

Usage

Examples

API Rate Limiting

Custom Rate Limiter

Service-Specific Rate Limits

Token Bucket Algorithm

Behavior

When RateLimitError is thrown:
  1. The job is moved back to the wait state
  2. A rate limit TTL is set on the queue
  3. Workers will wait before fetching new jobs
  4. The job’s attemptsMade counter is not incremented
  5. The job will be retried when the rate limit expires

Global Rate Limiting

Set a global rate limit on the queue:
Then workers will automatically respect this limit:

Worker-Level Rate Limiting

Combining with Other Limits

Monitoring Rate Limits

Dynamic Rate Limits

When to Use RateLimitError

Use RateLimitError when:
  • External API returns 429 (Too Many Requests)
  • Internal rate limits are exceeded
  • Service quota limits are reached
  • Need to throttle job processing
  • Protecting downstream services
Don’t use RateLimitError for:
  • Validation errors - use UnrecoverableError
  • Temporary delays - use DelayedError
  • Normal retry logic - use job attempts
  • Permanent failures - throw regular Error