Question #31 of 60•Caching•Medium• ~3 min read

Which caching pattern should you choose: Write-Through, Write-Back, or Cache-Aside?

Executive Takeaway

Compare data write flows, cache consistency guarantees, and crash risk profiles across standard caching strategies.

Architectural Breakdown & AnalysisFAANG Aligned

Selecting the correct cache update flow is critical to prevent data drift between cache keys and underlying databases.

1. Cache-Aside (Lazy Loading)

  • Read: App queries cache. On miss, app reads DB and populates cache.
  • Write: App writes directly to DB, then invalidates/deletes the cache key.
  • Pros: Resilient to cache crashes. Only requested data is cached.

2. Write-Through

  • App writes to Cache. Cache synchronously updates DB before returning success.
  • Pros: High consistency, read hits guaranteed.
  • Cons: Higher write latency.

3. Write-Back (Write-Behind)

  • App writes to Cache. Cache acknowledges immediately and writes to DB asynchronously in background batches.
  • Pros: Ultra-high write throughput.
  • Cons: Risk of data loss if cache node crashes before flushing to DB.
NOTE — Default Recommendation

Cache-Aside is the most common pattern for web applications due to simplicity and safety against cache failures.

Key Architectural Comparison

Caching PatternApp Write FlowDB Write FlowCache Stale WindowWrite Latency
Cache-AsideApp writes to DB.App invalidates/deletes cache key.Brief read window.Low.
Write-ThroughApp writes to Cache.Cache synchronously writes to DB.Zero stale data.High (Waits for DB commit).
Write-Back (Write-Behind)App writes to Cache.Cache asynchronously batches to DB.Eventual consistency.Lowest (Returns immediately).
Previous QuestionHow does OAuth 2.0 PKCE secure Single Page Applications (SPAs) & Mobile Apps?Next Question How does a Service Mesh (Istio / Envoy) simplify microservice traffic management?

Continue Learning on Being SDE

Explore deep-dive system architecture modules, low-level object-oriented designs, and interview cheat sheets.