STORAGE, CACHING & SEARCH · SUBTOPIC
Cache-Aside, Write-Through & Write-Back
Compare the three core read/write caching strategies and when to pick each.
BeginnerPart of Caching Strategies
Subtopics in Caching Strategies (2)
In plain words
Cache-aside checks your pocket first and only goes to the filing cabinet if it’s missing. Write-through updates both pocket and cabinet together. Write-back scribbles in your pocket and files it later.
Think of it like…
Keeping frequently used ingredients on the kitchen counter (Cache-Aside) vs. updating inventory books on every scoop (Write-Through).
Loading interactive diagram
Loading interactive exercise
Theory & how it works
How to update or invalidate on writes in Cache-Aside
When data changes in the DB, delete the cache key (DEL user:42) rather than writing the new value blindly - deleting avoids race conditions where two concurrent writers overwrite the cache in the wrong order.
Key points & practical guide
Summary checklist
- Cache-Aside is the default for 80% of apps
- Delete cache key on update rather than blind overwrite
- Never use Write-Back without persistence/AOF if data loss is unacceptable
When to use it
- Read-heavy services
- Expensive computed responses or DB aggregations
Watch out for
- Not setting a TTL - stale or unused data fills RAM forever
Quick check
Loading quiz