Skip to content
Ameen Abozaid
Planned lessonMID-040-L01

Stampedes

  • Lesson 1 of 5
  • Mid-level
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

explain a cache stampede and the three standard defences.

Planned topics

  • A stampede: a hot key expires and many requests miss at once, all hitting the database for the same row.
  • Locking: only one request rebuilds; the others wait or serve the old value.
  • Request coalescing (single flight): concurrent loads of one key share one call (Caffeine LoadingCache does this per instance).
  • Early refresh: refresh before expiry (refreshAfterWrite) or add random jitter to TTLs.
  • Per-instance coalescing still allows one load per instance; use a distributed lock for stronger protection.
Draft outline details

Demonstration

timeline: 500 requests at 12:00:00 when product:7 expires; with a lock, 1 database query instead of 500.

Check your understanding

Name two ways to avoid a stampede.

Show answer

Locking/coalescing, early refresh, TTL jitter.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.