Redis (Caching) 00:00:01 A bus at the wrong stop A parent walks toward stop four. The school bus has already reached stop five. The tracker knows, but one web server still has yesterday’s idea of fast: answer every request from memory. The transport team wants fast reads without giving one family another child’s route. First the service checks which bus the parent may follow. Then it can look up that bus’s last reported position. Store the observation time beside the coordinates. A fast cache hit can still return an old measurement. In this example the interface labels positions older than ten seconds so nobody confuses freshness with response time. 00:00:46 Follow one miss and one hit The first authorized lookup for bus eighteen finds no key in Redis. The application asks the authoritative tracker, gets stop five, and stores a copy with a ten-second expiration. This pattern is called cache aside. A second parent on the same route asks two seconds later. The service checks permission again, reads the cached position and skips the origin call. The benefit is the trip the tracker never had to serve. Now the bus moves to stop six, before the cached copy expires. A hit on stop five is expected under this choice. Where immediate correctness matters, such as a seat reservation, the write must consult its authority. 00:01:34 The key vanishes for two different reasons Expiration makes a key unavailable after its deadline. The next lookup can fetch a replacement. Ten seconds limits how long this cached copy survives, but cannot make an old measurement from the tracker ten seconds fresh. Memory can run out earlier. Redis can evict entries according to the configured policy when a write would push memory beyond the limit. An entry with time still left can disappear under an applicable eviction policy. If every cached position vanished tonight, tomorrow’s queries could rebuild them from the tracker. That makes eviction a tolerable miss. Storing the only copy of a permission grant in this cache would make eviction a different event entirely. 00:02:22 An entire school asks at once At the school bell, one popular key expires just as hundreds of parents refresh. Each request sees a miss. If each also queries the tracker, the quiet origin suddenly receives the whole crowd. Coalesce concurrent refreshes for that particular key. One caller starts the fetch. Others share its result or, if the product permits, see a clearly dated older position. Deadlines prevent those waiters piling up indefinitely. A lock held in one application process coordinates only that process. With two workers, two fills can still reach the tracker. Measure the remaining pressure before paying for coordination shared by the entire fleet. 00:03:11 Pull the cache plug Suppose ten thousand lookups arrive per second and ninety-nine percent hit in steady state. Roughly one hundred lookups reach the tracker. Take Redis offline and that same tracker could face ten thousand each second. The team caps origin traffic, serves a dated position when policy allows it, and tells the parent when tracking is temporarily unavailable. A fast service has to remain understandable on its slow day. The parent can now distinguish a fresh report from an old one. The tracker owns the fact, Redis holds a replaceable copy, and the application decides who may read it and how much uncertainty is acceptable.