Skip to content
learn
  1. Learn
  2. High Level System Design
  3. Caching

HLD-M05

Caching

Make reads fast and cheap with caches: why they work, the read and write patterns, eviction, invalidation, stampedes and hot keys, and Redis versus Memcached.

6 lessonsabout 70 min

Caching is the most powerful performance tool in system design, and the one most likely to cause subtle bugs. A cache in the right place can cut latency tenfold and take most of the load off a database; a cache used carelessly serves stale prices, logs people into the wrong account or collapses the database the moment it restarts.

This module builds the whole picture. You will see why skewed access makes caching work at all, how cache-aside, read-through, write-through and write-behind differ, how eviction policies decide what stays, why invalidation is famously hard, how to survive stampedes and hot keys, and when to reach for Redis or Memcached.

Lessons

  1. HLD-05.01 Why caching works A cache keeps a copy of data in a faster place, usually memory, so repeated reads skip the slow source. Beginner 8 min
  2. HLD-05.02 Caching patterns In cache-aside the application checks the cache, and on a miss reads the database and fills the cache. Intermediate 14 min
  3. HLD-05.03 Eviction policies When a cache is full it must evict something. Intermediate 10 min
  4. HLD-05.04 Cache invalidation and consistency The hard part of caching is keeping copies correct when the source changes. Intermediate 12 min
  5. HLD-05.05 Thundering herd, cache stampede and hot keys When a very popular key expires, thousands of requests miss at once and all hit the database together, which is a cache stampede. Advanced 12 min
  6. HLD-05.06 Distributed caches: Redis and Memcached Redis and Memcached are in-memory key-value stores used as shared caches. Intermediate 14 min

Start with lesson 1