Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Courses/Foundations of Scale
Lesson 8 of 16

Caching the read path

Serve repeated reads from memory and protect your database from load.

15 min read

Why caches work

Most systems read far more than they write, and reads are skewed: a small set of popular items gets most of the traffic. Keeping those items in memory makes reads around ten times faster and removes most of the load from the database.

Where to cache

Caches can sit at several layers, and they stack.

  • CDN at the edge: static files and public, cacheable responses close to users
  • In-memory cache (e.g. Redis) next to your services: hot rows, sessions, precomputed results
  • Local in-process cache: tiny, ultra-hot data such as configuration

Cache-aside and invalidation

In the cache-aside pattern the service reads from the cache first, falls back to the database on a miss, and writes the result into the cache with a time-to-live. The hard part is staleness: decide how old data may be, and either expire it with a TTL or delete the key when the source changes.

When the cache fails

A cache is a performance layer, so the system should keep working without it, just slower. But if the database was sized assuming a 90% hit rate, losing the cache can send ten times the traffic to it at once. Replicate important caches and size the database to survive a cold cache, or shed load while the cache warms.

Key takeaways

  • Cache what is read often and changes rarely
  • A cache hit rate of 85% cuts database load by almost seven times
  • Plan for a cold or failed cache: the database must survive it

Sign in to track lessons and earn badges.

DNS and content delivery networksCache invalidation and write patterns

Coming up

Course: 0/16 lessons · 0/10 challenges0%

Build it on the canvas, pass the review (70+) and mark it complete to count it toward the course badge.

  1. 4/10Design a Product CatalogServe read-heavy product pages with cache-aside over SQL and keep them fresh when a product is edited.Easy
  2. 5/10Design a Blogging PlatformModel posts and comments in SQL with the right indexes, then cache and CDN the read path.
Easy
All 10 challenges →