The cache hierarchy
Caches exist at every layer of the stack, each with different latency, capacity, and invalidation complexity:
| Layer | Example | Latency | Capacity |
|---|---|---|---|
| Browser cache | HTTP Cache-Control | 0 ms (local) | ~100 MB |
| CDN | Cloudflare, CloudFront | 5–30 ms | Petabytes |
| App cache | Redis, Memcached | 0.1–1 ms | GBs–TBs |
| DB buffer pool | Postgres shared_buffers | 0.01 ms | RAM-limited |
A cache hit at the CDN layer costs you ~10 ms and zero origin compute. A cache miss that hits a cold Postgres query costs 50–200 ms and a DB CPU spike. For a service handling 50k QPS, going from 80% to 95% CDN hit ratio saves ~750 req/s of origin load — often the difference between scaling up and not.
The rule: cache as close to the client as possible, invalidate as close to the data source as possible.
