Caching at Every Layer
Caching stores the result of an expensive operation so future requests return instantly without repeating the work. It exists at every layer: the browser caches responses via Cache-Control headers, a CDN caches content at edge locations, the application caches database results in Redis, and the database itself caches hot pages in its buffer pool. The hardest caching problem is invalidation — knowing when to evict stale data. Write-through caches update the cache on every write, staying consistent at the cost of slower writes. Cache-aside is the most common: read from cache, fall through to the database on miss, then populate the cache for next time. Use TTLs as a safety net so stale data cannot live forever even if invalidation logic misses.