This is a classic cache consistency problem.
#systemdesign #backendengineering #caching
This is a classic cache consistency problem.
Cache improves performance, but it also introduces a new challenge:
keeping cache and database in sync.
Let’s break it down simply 👇
1️⃣ What is cache consistency?
Cache consistency means
the data in cache should reflect the latest valid data in the database.
When they go out of sync, users start seeing stale data.
2️⃣ Common reasons this happens
Write goes only to DB
Application updates the database but forgets to update or invalidate the cache.
Cache TTL is too long
Data remains in cache even after it has changed in DB.
Multiple services updating data
One service updates DB, another service reads from cache without knowing.
Race conditions
Two requests update data almost at the same time and cache gets an older value.
3️⃣ Popular strategies to handle cache consistency
Cache Aside (Lazy Loading)
• App reads from cache
• On miss, reads from DB and updates cache
• On update, app deletes cache entry
Most commonly used and simplest to control.
Write Through Cache
• Write goes to cache first
• Cache updates DB synchronously
Ensures consistency but increases write latency.
Write Behind Cache
• Write goes to cache
• DB is updated asynchronously
Fast but risky if cache crashes before DB update.
4️⃣ Real interview takeaway
Cache is not just a performance tool.
It’s a data consistency responsibility.
In interviews, always mention:
• How cache is updated
• How stale data is handled
• Trade-offs between consistency and performance
That’s what differentiates a junior from a senior answer.
cache consistency
stale data problem
cache vs database
system design cache
cache invalidation
distributed systems caching
backend system design interview
#SystemDesign
#BackendEngineering
#Caching
#TechInterviews
SoftwareArchitecture
DistributedSystems
Comments
Comments from the original post on Instagram
No comments yet
