Caching Hierarchy Overview
What you'll learn: How systems use multiple layers of caches—from the client all the way to the database—to deliver fast responses.
The Core Idea
A caching hierarchy is a multi-layer strategy where data is stored at different levels of your architecture, each progressively closer to the end user. Instead of relying on a single cache, modern systems use layers of caches: browser cache, CDN, application server cache, distributed cache, and database cache. Each layer serves requests faster than the one behind it.
Think of it like a warehouse distribution system: you keep popular items in the store (browser), a local warehouse (CDN), a regional distribution center (app server cache), and finally the main warehouse (database). Customers get items fastest from the store, and you only go back to the main warehouse when absolutely necessary.
Why Multiple Layers?
Each layer has different characteristics:
- Browser cache: Instant, but only for one user
- CDN: Fast globally, great for static assets
- Application cache: Shared across users, flexible
- Database cache: Reduces query load at the source
By combining these layers, you reduce latency (from our earlier lessons), improve throughput, and handle higher QPS without overloading your database.
How It Works Together
When a request comes in, the system checks each cache layer from front to back. If found (a "cache hit"), return immediately. If not found (a "cache miss"), fetch from the next layer or ultimately the database, then populate the upper caches for future requests.
This hierarchy isn't just faster—it also provides graceful degradation (from our health check lessons). If one cache layer fails, requests can still succeed using other layers.
Key Takeaway: A caching hierarchy uses multiple cache layers from client to database, with each layer providing faster access than the one behind it, dramatically improving system performance and resilience.