Digital Product Engineering5.9 Caching Strategies
VOL. V · CH. 5.9 · BACKEND SYSTEMS

Caching Strategies

The single highest-leverage performance technique available to a backend — and the one Phil Karlton called one of the two hard problems in computer science.

DivisionBackend / Performance
DifficultyIntermediate
Prerequisites5.1
Related5.15 1.6
2 min read · 341 words

5.9.1Definition

Caching stores the result of an expensive operation — a database query, a rendered page, an API response — so a repeat request can be served instantly from memory instead of recomputed. Caches exist at multiple layers: in the browser, at a CDN edge (1.6), in an application-level store like Redis, or inside the database itself.

5.9.2Why It Exists

Most read requests ask for data that hasn't changed since the last time someone asked — recomputing it every single time wastes database load and adds latency for no benefit. Caching exists to exploit this repetition, at the cost of introducing the hardest problem in the discipline: knowing when cached data has gone stale and must be invalidated.

5.9.3Cache Layers & Invalidation Strategies

StrategyHow it worksRisk
Time-based (TTL)Cached value expires automatically after a fixed durationSimple but can serve stale data until expiry
Write-through invalidationCache explicitly cleared/updated when underlying data changesMore accurate, more code paths to keep correct
CDN edge cachingStatic or semi-static responses cached at edge nodes (1.6)Excellent for public, non-personalized content

5.9.4Common Mistakes

  • Caching personalized data at a shared layer (like a CDN) with no per-user key, serving one user's private data to another.
  • No invalidation path at all — data changes in the database but the cache continues serving the old value indefinitely until TTL expiry, which may be set far too long.
  • Caching too aggressively during development, masking real bugs because a stale cached response looks identical to a correct one.

5.9.5Best Practices

  • Cache the expensive, rarely-changing, widely-shared data first — that's where the leverage is highest.
  • Always include a clear invalidation path, not just a TTL, for any data that changes based on user action.
  • Key cached entries carefully to avoid cross-user data leakage in shared caches.
Real-World ExampleCloudflare's edge cache serves the vast majority of static asset requests for sites like Jakim Digital Solutions' portfolio directly from a nearby edge node, never touching the origin server at all for unchanged assets.