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 Pattern | App Write Flow | DB Write Flow | Cache Stale Window | Write Latency |
|---|---|---|---|---|
| Cache-Aside | App writes to DB. | App invalidates/deletes cache key. | Brief read window. | Low. |
| Write-Through | App 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). |