Why it matters

Well-designed caches make services scale. Poorly-designed caches serve stale data, cascade to origin under stampede, or hide bugs. Understanding cache layers is core system design skill.

Advertisement

The architecture

CDN cache: content delivery network with edge nodes globally. Static assets (images, CSS, JS) served from edge close to users. TTL-based eviction, cache-control headers.

Reverse proxy cache: NGINX, Varnish. Cache HTTP responses at the origin's perimeter. Can serve stale-while-revalidate for smooth expiration.

Caching layersCDN edgestatic assetsApp cacheRedis/MemcachedDB query cachematerializedEach layer traded latency for freshness; invalidation strategy determines correctness
Cache hierarchy.
Advertisement

How it works end to end

Application cache: Redis or Memcached in-memory. Cache computed results, session data, rate limit counters. Use key patterns and TTLs to organize.

Database query cache: materialized views, query result cache. Pre-computed to avoid repeat query cost.

Invalidation strategies: TTL (simplest, some staleness), write-through (update cache on write, always fresh but slow writes), write-behind (async update, potential loss), event-driven (invalidate on data change events).