Problem Statement
Explain strong vs eventual consistency for caches and when each is acceptable.
Explanation
Strong consistency means reads reflect the latest write. Achieving this via write-through and synchronous invalidation increases latency and coupling; reserve it for critical correctness paths like balances or entitlement checks.
Eventual consistency allows brief staleness to gain speed and resilience. Use it for catalogs, feeds, or search where minor delays are tolerable. Bound staleness with TTLs, revalidation, or read-after-write exceptions for the actor who made the change.
Code Solution
SolutionRead Only
readYourWrites(userId, key){ bypassCacheFor(userId,key,window=5s) }