Advanced
Open
Pro
Diagnosing a Stale-Read Race Condition
Your team uses cache-aside reads. On a database write, the application
does: db.update(product) ; cache.set(key, new_value) (it sets the
new value into the cache rather than deleting the key). Users
occasionally report seeing an old price for a few minutes after a
price change, even though the write itself succeeded and the TTL is
one hour.
- Construct a concrete interleaving of two concurrent requests that explains the bug.
- Explain why switching from
cache.set(...)tocache.delete(key)on write fixes this specific bug. - Does deleting instead of setting introduce any new problem? What would you tell the interviewer about the trade-off?
Share this question