Three patterns dominate cache design. Each trades write cost, read cost, and consistency differently. Pick based on your workload.

Cache AsideWrite-ThroughWrite-BehindApp reads cache, on miss reads DB, populates cacheEvery write hits cache + DB synchronouslyWrite to cache; async flush to DBSimple, stale on cache expiryStrong consistency, higher write latencyFast writes, data loss risk if cache dies
Three cache-integration patterns with tradeoffs
Advertisement

Cache Aside

App reads cache. Miss → read DB → populate cache. Most common. Simple. Writes go direct to DB; cache invalidated or expired.

Cache Aside

App reads cache. Miss → read DB → populate cache. Most common. Simple. Writes go direct to DB; cache invalidated or expired.

Advertisement

Write-Through

Every write goes to cache AND DB synchronously. Cache stays fresh. Write latency is DB latency + overhead.

Write-Behind

Write to cache; background writer flushes to DB. Fastest writes. Risk: cache crash before flush = data loss.

Read-Through

Cache Aside variant where cache library reads from DB on miss (not app). Cleaner separation.

Choose by workload

Read-heavy + tolerable staleness → Cache Aside. Strong consistency needed → Write-Through. Write-heavy + acceptable risk → Write-Behind.

Cache Aside for reads, Write-Through for consistency, Write-Behind for write speed.