Lesson 7 of 15
13. Caching at Scale

13.6 What is cache warming?

3 min read+10 XP

At the wedding: You don't open the doors to 500 guests with an empty fridge. The night before, you stock it with the dishes you know everyone will want.

In the system: Cache warming means filling the cache with the data you expect to be hot before real traffic needs it, so the first wave of users doesn't all miss.

When to warm:

  • Before a known event: the Big Sale starts at 8 pm; at 7:45, load the 200 sale products, their prices and the home page.
  • After a cache restart or a new node: a brand-new node is empty and would send every request for its slots to the database.
  • After a deploy that changes key formats (Chapter 12, section 12.9's versioned keys).

How:

  • From a list: the top N keys from yesterday's access stats, or the sale's product list.
  • By replaying traffic: send a sample of recent real requests through the new cache before switching users to it.
  • Gradually: shift traffic to a new cache node a little at a time, so it fills while the old path still serves most users.

Warm with jittered TTLs (Chapter 12), or everything you warmed will expire together: an avalanche on a timer. And don't warm everything: warming keys nobody reads just evicts the ones they do.

Memory code: "Stock the fridge before the guests arrive."