Caching
9 engineering logs on Caching. Newest first.
- Hot keys defeat consistent hashing
Why a perfectly balanced ring still sends one celebrity key to one node, why adding cache nodes makes no difference to that node, and the three ways to split a key that a hash function cannot split for you.
- Local cache plus distributed cache: the coherence bill nobody budgets for
Why adding an in-process cache in front of Redis turns one consistency problem into N, why a pub/sub invalidation that nobody retries is a guarantee you do not have, and why the local TTL is the real bound on how wrong you can be.
- Why your Redis is slow: it is single threaded and you sent it KEYS
Why one O(N) command blocks every other client on the server, which everyday commands are secretly linear, and why a p99 spike with flat CPU is almost always somebody scanning the keyspace.
- Cache invalidation is a distributed systems problem in a convenience costume
Why deleting a key after a write is a two phase commit you did not design, how the update-then-invalidate ordering produces permanent staleness, and why invalidating rather than updating is the one decision that reliably helps.
- Write-through, write-behind, write-around: picking wrong costs you consistency or throughput
What each write strategy actually guarantees when the process dies mid-operation, why write-behind is the only one that can lose acknowledged data, and why write-around is the right default more often than people expect.
- Negative caching: the misses cost more than the hits
Why a cache that only stores successes leaves the expensive path completely unprotected, how an attacker turns that into a denial of service with random keys, and why caching absence needs a different TTL than caching presence.
- Cache stampede: how one expired key takes down the database
Why TTL expiry is a synchronised event that sends every concurrent request to the origin at once, why the pileup amplifies itself while the recompute runs, and why jitter is the cheapest fix nobody applies.
- Implementing LFU Cache in O(1) Time: A Hands-on Breakdown
LFU evicts the least popular key, not the oldest. The O(1) version needs two hash maps and linked lists per frequency bucket.
- Scaling a distributed cache: Why consistent hashing is mandatory
Why modulo-based cache sharding fails in production and how consistent hashing with virtual nodes protects your database.