XFetch prevents cache stampedes in lock-free stores like Memcached by having each request independently sample an exponentially distributed early refresh window scaled by the item’s last recomputation time Delta, holding expected duplicate refreshes to e - 1/e (about 2.4 processes) at any request rate n. By contrast, naive TTL expiry triggers n concurrent recomputations (for instance, 10,000 workers piling onto a 1-minute query), and the uniform early-expiration heuristic used in Perl’s CHI and Drupal requires a 50-minute early refresh window just to shrink a 10,000-worker stampede down to 100.
Vattani (Goodreads), Chierichetti (Sapienza University of Rome), and Lowenstein (Bugsnag) proved in VLDB 2015 that the exponential distribution is theoretically optimal when the cache server cannot track request arrival rates, and verified it against a week of production traffic from www.goodreads.com.
- Rate-independent stampedes: Under
Exp(lambda)with defaultlambda = 1(beta = 1), expected stampede size stays at 2.4 processes even atn = 10,000requests per recomputation, with an expected early refresh gap of onlyln(10,000) ≈ 9.2recomputation units. - Goodreads production trace (
Delta = 10s,n ≈ 140):Exp(1)kept most refreshes at size 1 or 2 and never exceeded 8, whereas uniformU(0, 10)andU(0, 20)averaged near 10 and spiked past 20. - Slow-query resilience (
Delta = 60s,n ≈ 840):Exp(1)kept every stampede at or below 10 (averaging under 5 with under 5 minutes of early refresh), while uniformU(0, 10)andU(0, 20)spiked over 80 and 50 concurrent refreshes. - Traffic bursts (
50 -> 500requests): In synthetic regime-switching bursts (p = 0.1),Exp(1)remained virtually unaffected whileU(0, 10)peaked around 70 andU(0, 20)around 45.
How It Works
Instead of coordinating workers with distributed locks (which double cache writes, fail open or stall when a lock holder crashes, and leave waiting clients empty-handed) or maintaining external cron warmers, XFetch stores (value, Delta, expiry) alongside the key, where Delta is how long the previous recomputation took.
On every read, a caller draws a uniform random value rand() in (0, 1] and refreshes early if:
Time() - Delta * beta * ln(rand()) >= expiry
Because ln(rand()) is negative, -Delta * beta * ln(rand()) draws an exponentially distributed future lookahead from Exp(1/beta) scaled by Delta. Far from expiry, almost no caller triggers a refresh. As expiry nears, the probability rises exponentially (e^{-lambda * y} at y recomputation units before expiry), and hot keys with more arrivals draw more samples before expiry hits. Once one worker recomputes and writes the fresh value and updated Delta (optionally extending ttl by expiry - Time() so early refreshes do not drift schedules), subsequent callers see a fresh expiry and skip recomputation.
Key Findings
The authors prove (Theorem 8) that no rate-oblivious gap distribution can beat Exp(lambda): bounding the early expiration gap to (1/lambda) log n forces an expected stampede size of at least e^{Omega(lambda)}, which Exp(lambda) matches up to constants ((e^lambda - 1)(1/lambda + 1/e)).
In practice, tuning beta = 1/lambda is simple and optional. On the Goodreads 10-second workload (n ≈ 140, burstiness sigma_I ≈ 3.6), default beta = 1 kept stampedes at or below 8, while raising beta to 1.5 pushed the average stampede size below 2. Knowing n approximately can shave the theoretical early gap down to O(log log n) (or O(log* n) with exact rates), though the authors note real traffic rates fluctuate too unpredictably for log* n schemes to pay off.
Caveats and Builder Takeaway
- Not strict mutual exclusion: XFetch reduces expected concurrency to ~2.4 workers probabilistically; if a downstream write is non-idempotent or requires strictly one recomputation per expiry, pair it with locking or in-process request coalescing.
- Cold-start and stale-
Deltasensitivity: The first miss has noDelta, and if a normally fast query suddenly stalls 10x slower right at expiry, the cachedDeltaunder-scales that cycle’s lookahead window. - Early refresh scales with
log(n): Hot keys refresh severalDeltaintervals beforeexpiry(beta * Delta * ln(n)), which trades slight freshness slack for stability in high-throughput key-value layers.
If you store keys in Memcached or Redis without server-side locks, adding Delta and the one-line -Delta * beta * ln(rand()) check is the cleanest way to kill thundering herds before they overload your origin database.


