Applying Jitter

Jitter is an optional post-processing step that decorates any backoff strategy. It adds controlled randomness to the delay returned by the selected strategy without replacing that strategy.

This helps reduce synchronized retry bursts and the thundering herd problem by spreading retries across a randomized window.

Basic Usage

use Kodefarmers\Cadence\Enums\JitterType;

Cadence::driver('exponential')->jitter();

Cadence::driver('linear')->jitter(JitterType::EQUAL);

Available Jitter Algorithms

Cadence currently supports two jitter algorithms:

AlgorithmDescription
JitterType::FULLRandomizes the entire delay between 0 and the calculated delay.
JitterType::EQUALPreserves roughly half of the calculated delay while randomizing the rest.

Every built-in backoff strategy can be combined with jitter. JitterType::FULL is used by default.

Full Jitter

Full jitter randomizes the entire delay between 0 and the calculated delay.

use Kodefarmers\Cadence\Enums\JitterType;

$cadence = Cadence::driver('exponential')->jitter(JitterType::FULL);

Example: If the calculated delay is 8 seconds, the actual delay will be a random value between 0 and 8 seconds.

Equal Jitter

Equal jitter preserves roughly half of the calculated delay while randomizing the rest.

use Kodefarmers\Cadence\Enums\JitterType;

$cadence = Cadence::driver('exponential')->jitter(JitterType::EQUAL);

Example: If the calculated delay is 8 seconds, the actual delay will be at least 4 seconds plus a random value between 0 and 4 seconds.

When to Use Jitter

Use jitter when:

  • Multiple clients may retry the same operation simultaneously
  • You want to distribute retries across a time window
  • You need to reduce the thundering herd effect on downstream services
  • Your application handles high-concurrency scenarios