Skip to content

How to prevent it

Mutex on refresh, jitter on TTL, stale-while-revalidate.

Killing the herd

  1. Single-flight / mutex

    In Redis: SET lock:key 1 NX EX 10. Winner refills, others wait or serve stale.

  2. Jitter TTL

    If TTL is 60s, use 60 ± 6s. Spreads expiry across 12 seconds.

  3. Stale-while-revalidate

    Serve stale for up to 5 minutes while refreshing. Users never wait.

  4. Warm cache before expiry

    Cron every 30s re-fills known hot keys before they expire.

  5. Backpressure

    Limit concurrent origin queries via a semaphore. Reject excess.

  6. Never broadcast

    Push invalidation sends "revalidate", not "evict". Let the cache refill on next read.