← Lessons

quiz vs the machine

Silver1060

System Design

The Cache Hierarchy From CPU to CDN

Every layer between a processor and a faraway database is a cache trading size for speed.

4 min read · intro · beat Silver to climb

One Idea Repeated at Every Scale

Caching is the same trick applied over and over: keep a small fast copy of data close to where it is used. The numbers change at each layer but the shape does not.

Walking Up the Ladder

  • CPU registers and L1 to L3 hold bytes and respond in nanoseconds.
  • Main memory holds gigabytes and responds in tens of nanoseconds.
  • Local disk and SSD trade speed for far more capacity.
  • Application caches like an in process map or a Redis node sit near the service.
  • The database is the slow authoritative store the caches protect.
  • The CDN pushes copies to edge locations near the user.

Why the Pattern Holds

Each level is smaller and faster than the one below and serves as a shield for it. A hit at any level avoids paying the cost of every level beneath. The art of design is deciding what to keep hot at each tier so the slow layers see as little traffic as possible.

Key idea

Caching is one idea repeated across scales: a small fast copy near the consumer that shields the larger slower store below it.

Check yourself

Answer to earn rating on the learn ladder.

1. What property is shared by every layer in the cache hierarchy?

2. What is the main benefit of a hit at a higher cache level?