Menu

Earn Premium with Referrals

Invite your friends and earn Premium rewards through our referral program.

See how it works and start inviting friends.

Jitter
HLD

Jitter

The randomization that prevents synchronized stampedes — small randomness, outsized stability.

The Problem: Perfect Synchronization

 deterministic systems do identical things simultaneously:

 500 instances poll the config service every 60.000s:
   t=0     all 500 hit at once   ← spike
   t=60    all 500 again         ← spike
   ...forever

 retries make it worse — failures synchronize clients:
   outage → everyone's retry timer starts together →
   simultaneous retry wave → fail → synchronized backoff →
   next wave TOGETHER.

 [load without jitter]        [with jitter]
 ▲  ▲▲  ▲▲▲                   ▲ ▲ ▲ ▲ ▲ ▲ (smooth)
 ███ ███ ███                  ▄▄▄▄▄▄▄▄▄▄▄
 spikes = self-inflicted outages

The Fix: Deliberate Randomness

 add randomness to every scheduled repetition:

 FULL JITTER (recommended default):
   sleep = random(0, base × 2^attempt)
   spreads across whole range; best empirical results

 EQUAL JITTER:
   sleep = base/2 + random(0, base/2)
   keeps a floor delay; tighter pacing control

 DECORRELATED:
   sleep = min(cap, random(base, prev_sleep × 3))
   adapts to observed timing; no shared clock assumptions

 same idea beyond retries:
 - cron jobs:      ±random minutes ("0 * * * *" + jitter(300s))
 - cache expiry:   TTL ± 10% (no synchronized mass-expiry!)
 - heartbeats:     interval ± noise
 - autoscaling polls, backup jobs, certificate renewals...

Cache Expiry: The Sneaky Case

 100k keys cached with EXACT ttl=3600:

 loaded at deploy time t0 → ALL expire at t0+3600
 → thundering herd to DB at that instant → brownout every hour,
 forever, mysteriously aligned with... nothing visible.

 fix: ttl = 3600 + random(-300, +300) at write time.
 one line. eliminates an entire incident class.
WhereWithout jitterWith
Retriespulsing herdssmooth decay
Cron fleetsaligned spikeslevel load
TTL expiryperiodic brownoutsflat misses
Reconnect stormssynchronized floodsgradual return

Interview Framing

“Every hour your database gets slammed for 30 seconds” scored diagnosis: synchronized TTL expiry as first hypothesis (cron alignment second), prescribe per-key jittered TTLs with concrete numbers, generalize to heartbeat/polling jitter proactively. This is a beloved interview puzzle precisely because the fix is one line and the diagnosis requires seeing synchronization everywhere — train the eye.

My Private Notes

Notes are auto-saved locally to this device.