Distributed Cache (Redis) 00:00:01 One profile, three possible outcomes A reader asks for user one hundred twenty-three. A distributed cache can return the current profile quickly, miss and defer to the database, or return an older version that remains eligible under its policy. A phone, browser or other service asks for user 123. The application organises the rest. The key was never stored, expired or was evicted. Misses are normal. Count them. Store it with one hour to live. a forgotten delete cannot last for ever. This first read was slow. The next one is a hit. The database owns the authoritative profile in this design. Cache hit rate measures saved work; it does not establish freshness or guarantee that misses fit the database's peak capacity. 00:00:47 The email changes while another write is in flight Two updates can finish their cache writes in the opposite order from their database commits. Attach a monotonic source version to each representation and check it on the cache update. The user changes an email address. The change is durable and has version 8. Only if 8 is newer than the version there. two writers may finish in a different order here. The price is two waits and memory for values nobody may read. Make the source commit, cache update and failure recovery contract explicit. A process failing between two stores can leave a stale copy even when both individual systems work correctly. 00:01:22 A replica becomes the new cache primary The cache divides key slots among primaries and replicates them across failure boundaries. A replica receiving a write is different from a replica that has applied and can serve the latest version. Only one node accepts writes for a slot, so there are no conflicting orders. Another zone, so one building cannot take both. The answer resets the timer. They refresh the map and go on. A failover can resurrect stale cached data if the replica lags. Protect important reads with appropriate source versions, invalidation or a rebuild policy, and let clients refresh their routing maps. 00:01:56 Thousands of readers miss one hot profile The profile expires just as a popular event starts. Identical misses can all reach the same database row. Let a bounded single-flight operation share one refill among waiting readers. A popular key has just expired. And thousands more. The database returns the five-kilobyte profile in this example. The leader fills the cache and releases the waiting readers. Everyone waiting gets the same value. Give waiters a deadline and handle the refill owner's failure. An application still needs a safe degraded answer if the authoritative store cannot keep up. 00:02:29 An older refill races with an invalidation The database commits a newer profile, then a change event reaches the cache. A slower reader that started before the change can still return carrying the old value. Simply deleting a key once may not close that race. The cache still has version 1. Until now a reader could still get v1. This delay needs an alert. As intended. A slow reader holding v1 would be refused here. Guard fills by source version and monitor propagation lag. This prevents an older response from re-establishing a version you already know is obsolete.