Skip to main content

What is Jitter?

Jitter is the technique of adding randomness to retry timing. Instead of all rate-limited clients retrying at exactly the same time, jitter spreads retries across a time window. This prevents the thundering herd problem where synchronized retries cause traffic spikes.

The Thundering Herd Problem

Without jitter, rate-limited clients retry simultaneously:
This creates:
  • Network congestion: Burst of simultaneous requests
  • Database contention: High OCC conflicts
  • Resource spikes: CPU and memory usage peaks
  • Cascading failures: The spike might trigger more rate limits

Solution: Add Jitter to Retries

Add randomness to the retry delay:

Jitter Strategies

1. Full Jitter

Randomize across the entire retry window:

2. Proportional Jitter

Add jitter proportional to the wait time:

3. Decorrelated Jitter

Use the previous retry time to calculate the next:

Fixed Window: Automatic Jitter

The fixed window strategy includes built-in jitter for the window start time:
From the README:
For the fixed window, we also introduce randomness by picking the start time of the window (from which all subsequent windows are based) randomly if config.start wasn’t provided. This helps from all clients flooding requests at midnight and paging you.
From the source code (shared.ts:146-149):
The window start is randomized within the period, distributing resets across time.

Custom Window Start

You can specify an exact window start time to control reset timing:
Caution: Using a fixed start time means all clients reset simultaneously. Only use this when you specifically need synchronized resets (like daily quotas).

Client-Side Retry Pattern

Implementing jittered retries on the client:

Server-Side Retry with Scheduler

Use ctx.scheduler with jitter for server-side retries:

Jitter vs Reservations

Use Jitter When:

  • You want clients to retry independently
  • The order of operations doesn’t matter
  • You’re okay with some operations failing
  • You need simple retry logic

Use Reservations When:

  • You need guaranteed execution
  • Order matters (fair queueing)
  • You can’t afford operation failures
  • You’re dealing with large batch operations
See the Reservations guide for more on capacity reservation.

Complete Example

Best Practices

  1. Always add jitter: Don’t rely on clients retrying at the same time
  2. Use appropriate jitter size: Balance between spreading load and user experience
  3. Combine with exponential backoff: For repeated failures, increase delay exponentially
  4. Consider using reservations: For critical operations that must succeed
  5. Monitor retry patterns: Track jitter effectiveness in your metrics
Jitter is most effective when combined with other rate limiting strategies. See Sharding for handling high throughput and Reservations for preventing starvation.