Course contentsShow
← Web Development
Lesson 1689 of 2,98231. Error Handling and ResilienceFree lesson

Adding Jitter to Retry Delays

Prevent thundering herd problems by randomizing retry delays with jitter.

Adding Jitter to Retry Delays

What you'll learn: How to prevent multiple clients from retrying at the same time by randomizing retry delays.

The Thundering Herd Problem

You've learned about exponential backoff — doubling your wait time with each retry (1s, 2s, 4s...). But imagine 1,000 users all hit your server at the same moment, get an error, and all retry after exactly 1 second. Then they all retry again at 2 seconds, then 4 seconds. Your server faces synchronized waves of traffic, defeating the purpose of the delay.

This is the thundering herd problem: when multiple clients retry simultaneously, creating traffic spikes that may overwhelm the recovering server.

What Is Jitter?

Jitter means adding controlled randomness to your retry delays. Instead of waiting exactly 2 seconds, you might wait anywhere from 1.5 to 2.5 seconds. This spreads out retry attempts over time, preventing synchronized waves.

Why It Matters

When a server goes down or slows down, thousands of clients might be affected simultaneously. Without jitter, they'll all retry together in lockstep. With jitter, their retries are staggered naturally, giving the server breathing room to recover.

Think of it like elevator usage: if everyone in a building left work at exactly 5:00 PM, the elevators would be overwhelmed. But when people leave between 4:45 and 5:15, the system handles the load smoothly.

Implementation Concept

Take your exponential backoff delay and multiply it by a random factor between (for example) 0.5 and 1.5, or add a random number of milliseconds. The exact randomization strategy varies, but the goal is the same: spread out the retries.

Key Takeaway: Adding jitter to retry delays randomizes when clients retry, preventing thundering herd problems and helping servers recover gracefully under load.