A cache across many machines: partitioning, eviction, replication and hot keys.
“Design a distributed cache, like Memcached or Redis Cluster.”
It is short on purpose. Your first job is to make it specific.
| What they check | Why it matters |
|---|---|
| Knowing what a cache is for | A cache is allowed to lose data and to be a little stale. Saying this out loud, and designing around it, is what separates it from a key-value store. |
| Partitioning without a mass reshuffle | Hash mod N empties the cache when one node joins. You must explain consistent hashing or hash slots and what a new node costs. |
| Eviction and memory | A cache is always full. The interviewer wants to hear how you choose what to throw away, cheaply, and how expiry works. |
| Hot keys and stampedes | The cache fails in the interesting ways: one key melts one node, or a node dies and the database is flooded. |
| Consistency with the database | Stale data is allowed, but wrong forever is not. You need a clear rule for invalidation and a safety net (TTL). |
A distributed cache is a fleet of in-memory machines that sit in front of a database. Keys are spread over the machines by consistent hashing (or hash slots), so adding a node moves only a small slice. The application uses it cache-aside: read the cache, on a miss read the database and fill the cache.
| Step | Minutes | What to get done |
|---|---|---|
| 1. Clarify | 4 | Cache-aside or built in, value size, scale, staleness allowed, persistence, what a cache failure may do. |
| 2. Estimate | 3 | Working set in memory, node count, ops per node, and the hit ratio that protects the database. |
| 3. API and data | 4 | get, set with TTL, delete, batch get. What one entry holds in memory. |
| 4. High-level design | 8 | Clients, routing, shards with a replica, config service, and the miss path to the database. |
| 5. Deep dives | 15 | Partitioning and rebalancing, eviction and memory, hot keys, failure and consistency. |
| 6. Scale and failures | 8 | Node loss, avalanche, network, monitoring, security. |
| 7. Wrap up | 3 | Recap, the trade-offs, and what you would add next. |
| Ask | Why you ask it | Typical answer | How it changes the design |
|---|---|---|---|
| Is this a cache in front of a database, or the main store for this data? | A cache may lose data. A store may not. This one question separates the two designs. | A cache. The database is the source of truth, and any key can be rebuilt from it. | No need for durable writes or quorums. Replication is only there to make failover quick. |
| Who uses it, and through which API? | Decides whether we build a client library, a proxy, or both. | Many internal services, through a client library, in one region. | A smart client does the routing. A proxy tier can be added for languages without a good client. |
| What operations, and what sizes? | Value size changes memory layout and network cost. | get, set with a TTL, delete, and batch get. Values up to 1 MB, about 1 KB on average. | Small values: a hash table with slab-like memory pools. Cap the size and say so. |
| How much traffic and how much data? | Sets the node count and shows whether CPU or memory is the limit. | Peak 1 million ops/s, 90% reads, a working set of 10 TB. | Memory is the limit. Roughly a hundred nodes, each with moderate traffic. |
| What latency do we need? | A cache that is slow is not a cache. | p99 under 2 ms inside the data centre. | One network hop, no cross-zone calls on the hot path, short client timeouts. |
| How stale may a read be? | Decides the invalidation scheme and the TTLs. | A few seconds of staleness is fine, but not wrong data for hours. | Cache-aside with delete on write, plus a TTL as a safety net. |
| What if the cache is unavailable? | Defines whether the cache is a performance helper or a hard dependency. | The product must keep working, slower. The database must not be crushed. | Client timeouts, circuit breaker, stampede protection, and a limit on database traffic. |
| Must data survive a restart? | Persistence adds cost and complexity. | No. A cold start is acceptable if we can warm it. | Memory only. Optional snapshots to speed up recovery, plus a warming plan. |
| Is it shared by many teams? | Multi-tenancy needs isolation and quotas. | Yes. One noisy team must not evict another team's data. | Key prefixes per tenant, memory quotas, and per-tenant rate limits. |
| One region or several? | Cross-region latency is far larger than the cache latency target. | One region first. Each region has its own cache. | No cross-region replication of cache data. Use an invalidation stream if needed later. |
| Assumption | Value |
|---|---|
| Working set (values) | 10 TB |
| Average value size | 1 KB |
| Per-key overhead (key, pointers, TTL, LRU data) | about 64 bytes |
| Usable memory per node | 100 GB (on machines with more, headroom kept for the OS and fragmentation) |
| Peak client traffic | 1 million ops/s, 90% reads and 10% writes |
| Operations one node can serve (illustrative) | about 100,000 per second |
| Copies | 1 primary and 1 replica per shard |
| Hit ratio target | 95% |
| Client app servers | 2,000, each keeping 5 connections to each node |
| What | Maths | Result |
|---|---|---|
| Entries in the working set | 10 TB ÷ 1 KB = 10^13 ÷ 10^3 | 10 billion entries |
| Memory used by overhead | 10 billion × 64 B | 640 GB (about 6% more) |
| Memory for one copy | 10 TB + 0.64 TB | about 10.6 TB |
| Primary nodes | 10.64 TB ÷ 100 GB per node | about 106, round to 110 |
| Nodes including replicas | 110 primaries × 2 | 220 machines, 22 TB of RAM |
| Reads and writes per second | 1M × 90% and 1M × 10% | 900,000 reads and 100,000 writes |
| Operations per primary | 1M ÷ 110 | about 9,100 per second (9% of a node's limit) |
| Read bandwidth out of the cache | 900,000 × 1 KB | 900 MB/s, about 7.2 Gbit/s in total, 65 Mbit/s per node |
| Database load at 95% hits | 900,000 reads × (1 − 0.95) | 45,000 reads per second reach the database |
| Database load at 90% and at 99% | 900,000 × 0.10 and × 0.01 | 90,000 and 9,000 reads per second |
| Value of each hit-ratio point | 900,000 × 1% | 9,000 database reads per second saved per point |
| Hash slots per node (Redis Cluster style) | 16,384 ÷ 110 | about 149 slots per primary |
| A hot key at 10% of reads | 900,000 × 10% | 90,000 ops/s on one node, 90% of its limit |
| Adding one node with hash mod N | 110 ÷ 111 | 99.1% of keys move: nearly 890,000 reads/s become misses |
| Adding one node with consistent hashing | 1 ÷ 111 | 0.9% of keys move, about 96 GB, and about 8,100 reads/s become misses |
| Connections | 2,000 servers × 110 nodes × 5 | 1.1 million connections, 10,000 per node |
| Method | Path | Request | Response | Notes |
|---|---|---|---|---|
| GET | /v1/cache/{key} | none | 200 { value, ttl_remaining } or 404 | A miss is a normal answer, not an error. The client then reads the database. |
| PUT | /v1/cache/{key} | { value, ttl, if_absent? } | 204 | Always send a TTL. if_absent is for locks and single-flight. Values over the size cap get 413. |
| DELETE | /v1/cache/{key} | none | 204 | Idempotent. Used after a database write. |
| POST | /v1/cache/mget | { keys: [...] } | 200 { hits: {...}, misses: [...] } | The client groups keys by node and sends one request to each node in parallel. |
| POST | /v1/cache/{key}/incr | { by, ttl? } | 200 { value } | Atomic on one node. Used for counters and rate limits. |
| Held per entry in memory | Type | Notes |
|---|---|---|
| key | bytes, up to 250 | Includes a tenant prefix so teams cannot collide. |
| value | bytes, up to 1 MB | Opaque to the cache. Compressed by the client if large. |
| expires_at | timestamp | Checked on read (lazy expiry) and by a background sweep. |
| last-access info | a few bytes | A timestamp or a small counter, for LRU or LFU decisions. |
| hash-table link | pointer | The bucket chain. This and the fields above are the per-entry overhead. |
| Cluster state | Holds | Where |
|---|---|---|
| Ring or slot map | Which node owns which keys, plus replicas | Every client, loaded from the config service and refreshed on change |
| Membership | Which nodes are up | Config service plus gossip or a health checker |
| Replication stream | Writes from a primary to its replica | A buffer on each primary |
| Hot-key stats | Sampled counts of the busiest keys | Each node, reported to monitoring |
value = cache.get(key)
if value is null:
value = db.read(key) // the source of truth
cache.set(key, value, ttl = 300 + jitter) // jitter: spread expiry times
return value
on write:
db.write(key, newValue) // 1. write the database first
cache.delete(key) // 2. then delete the cache entry| Component | What it does |
|---|---|
| Client library | Hashes the key, finds the shard from its copy of the map, sends the request, and handles timeouts, retries, batching and a small local cache. |
| Shard (primary + replica) | A primary serves reads and writes for a slice of the keys. An async replica takes over if the primary dies. Replicas can serve reads for non-critical keys. |
| Slot map or ring | Says which shard owns which keys. Versioned, so a client can tell when its map is out of date. |
| Config service | A small, reliable store (a consensus system) that holds the map and membership. It is not on the hot path: clients cache the map. |
| Health checking and failover | Detect a dead primary, promote its replica, publish a new map. Takes a few seconds. |
| Eviction and expiry (per node) | Keep memory under the limit by dropping approximate least-recently-used keys, and remove expired keys. |
| Stampede and hot-key protection | Single-flight on a miss, jittered TTLs, a local cache for hot keys, and copies of very hot keys. |
| Database | The source of truth. Protected by a circuit breaker and a request limit, so a cold or failed cache cannot overload it. |
The problem: 10 billion keys must be spread over 110 shards, found without a central lookup, and adding or removing a node must not empty the cache. A cold cache means the database takes the whole load.
| Option | How it works | Good | Bad |
|---|---|---|---|
| hash(key) mod N | Divide the hash by the node count and take the remainder. | Trivial and even. | A new node changes N, so about 99% of keys get a new owner and miss at once. Unusable at this size. |
| Consistent hashing with virtual nodes | Nodes and keys sit on a ring. Each machine owns many small tokens. A key goes to the next token clockwise. | A new node takes about 1/N of the keys, from many nodes at once. Even load. | The client needs the whole ring. Moving data between nodes is a separate job, or you accept misses. |
| Fixed hash slots (Redis Cluster style) | Hash the key into one of 16,384 slots. A table maps slots to nodes. Moving capacity means moving slots. | Easy to reason about and to move one slot at a time. Nodes can redirect with MOVED and ASK. | Needs the table to be kept correct. Slot count limits the shard count (about 1,000 shards). |
| A proxy tier that routes | Clients talk to stateless proxies (twemproxy or mcrouter style), which hold the map and route. | Thin, simple clients in any language. One place to change routing, pool connections and cut connection counts. | An extra network hop on every request, and the proxies must be scaled and kept available. |
I would use fixed hash slots: every key maps to one of 16,384 slots, and each shard owns about 149 of them. A smart client library keeps the slot map, so there is no extra hop, and it learns of changes from MOVED replies and the config service. Consistent hashing with virtual nodes gives the same property (about 1/N of keys move). Both are far better than mod N. See Consistent Hashing.
When we add a node, we move slots to it a few at a time. For each slot the old owner answers keys it still has, and replies ASK for keys already moved, so the cluster keeps serving during the move. About 96 GB (0.9% of the data) travels, and we can copy it at a limited rate, roughly 200 MB/s, in about 8 minutes, so the new node starts warm instead of empty.
| Event | What happens | Keys that become misses |
|---|---|---|
| Add a node with mod N | Almost every key changes owner | about 99% (110 ÷ 111) |
| Add a node with slots or a ring | Only the slots given to the new node move | about 0.9% (1 ÷ 111) |
| Add a node, copy slots first | Data is streamed before the owner changes | close to 0% |
| A node dies, replica promoted | Replica has almost all of its data | only the last few writes |
| A node dies, no replica | Its slots are empty until refilled | about 0.9%, refilled from the database |
The problem: The cache is always full, so every insert means dropping something. The method must be O(1), cheap in memory, and good at keeping what will be read again. Expired keys must also be removed without scanning everything.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Exact LRU (hash map + linked list) | On each access move the entry to the front. Evict from the tail. | Exact. Simple to explain, O(1). | Two pointers per entry (extra memory), and every read changes shared structures, which needs locking. |
| Approximate LRU with sampling | Keep a last-access time per entry. To evict, sample a few random keys (say 5) and drop the oldest of them. | No list, tiny metadata, no write on the read path other than a timestamp. Very close to true LRU. | Not exact. Quality depends on the sample size. |
| LFU (least frequently used) | Keep a small, decaying access counter per entry. Evict the lowest counts. | Resists scans and one-off bursts that pollute LRU. | Needs decay or old popular keys stay forever. Slow to adapt when popularity shifts. |
| TTL-only (no eviction) | Rely on expiry to free memory. Reject writes when full. | Predictable. | When full, the cache stops accepting new data. Only good for a small, well-bounded set. |
At 10 billion entries, two list pointers per entry is 160 GB of extra memory, and a lock on every read. Sampling avoids both. Each entry keeps a small access time, and when memory is full we sample a handful of keys and evict the oldest. That is almost as good as exact LRU. See Cache Eviction Policies for the policies and LRU Cache Design for the exact structure.
Expiry uses two tricks together. Lazy: when a key is read and has expired, delete it and return a miss. Active: a background job samples keys that have a TTL, deletes the expired ones, and repeats if many were expired. A timing wheel or a min-heap of expiry times is an alternative that finds the next key to expire directly, at some memory cost.
| Memory problem | What it looks like | Fix |
|---|---|---|
| Fragmentation | Free memory exists but is in small gaps | Slab classes (fixed chunk sizes), a good allocator, or active defragmentation |
| Big keys | One 100 MB value blocks the node while it is read or deleted | Cap value size, split big values, delete lazily in the background |
| Eviction storms | A scan of rarely used keys pushes out the useful ones | LFU, or admission control (only admit a key on its second request) |
| Memory accounting | Overhead is bigger than expected, node runs out of RAM | Count overhead per entry, keep headroom (about 10 to 20%), set a hard limit and an eviction policy |
The problem: Traffic is not even. One celebrity profile, one flash-sale item or one config key can take 10% of all reads. At 90,000 ops/s it uses 90% of one node while the other 109 are nearly idle, and adding nodes does not help because a key lives on exactly one node.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Do nothing, buy a bigger node | Give the hot node more CPU and network. | No code change. | Does not scale: one key is still bounded by one machine. Expensive. |
| Local cache in the app server (L1) | The client library keeps hot keys in its own memory for a second or two. | Removes the traffic before it reaches the network. Near-zero cost. Scales with app servers. | Up to a TTL of staleness, and memory on every app server. Invalidation is hard. |
| Several copies of the hot key | Store the key as key#1 … key#k on different nodes. Readers pick one at random. Writers update all. | Spreads reads over k nodes with no staleness beyond replication. | Writes cost k times as much. You must know which keys are hot and keep the copy list. |
| Read from replicas | Allow reads to go to the shard's replica as well as the primary. | Doubles the read capacity of that shard, with no key changes. | Replicas are slightly behind. Only two copies, so a limited gain. |
First find them. Each node can sample a small fraction of requests into a counter (a count-min sketch is a good fit, see Count-Min Sketch), and clients can count what they read. Report the top keys to monitoring and to the client library, which then marks them hot.
For a hot key, the app server serves it from its own memory for about 1 to 2 seconds. With 2,000 app servers, a key with 90,000 reads/s drops to about 2,000 per second (one refresh per server per second), a cut of about 98%. For keys too hot even for that, or too large for L1, keep 4 copies on different nodes, so each takes 22,500 ops/s. Try it in the playground below.
The problem: A node can die, and then a slice of the keys misses together and the database takes the load. Separately, the cache can hold stale data after a write. Both must stay bounded, because the cache must make the system faster, never wrong forever or down.
| Option | How it works | Good | Bad |
|---|---|---|---|
| Cache-aside with delete on write | Write the database, then delete the cache entry. Readers refill on a miss. | Simple. Cannot leave a wrong value in the cache for long. | A small race can refill with stale data. Needs a TTL as a safety net. |
| Write-through | Write the cache and the database together, in one code path. | The cache is warm after a write. | Two writes to keep in step. If one fails, they disagree. Caches data that may never be read. |
| Write-back (write-behind) | Write the cache, and flush to the database later. | Very fast writes. | Data loss if the cache dies. Not suitable when the cache is not the source of truth. |
| Invalidation from the database log | Read the database change log (CDC) and delete or update cache entries from it. | Catches every write, including from other services. Fixes the race. | More moving parts. A small delay between write and invalidation. |
The race to know: reader A misses and reads the old value from the database. A writer then updates the database and deletes the key. Reader A now writes the old value into the cache. It stays wrong until the TTL. This is rare, so we accept it, and the TTL (5 minutes, with jitter) bounds it. If it matters, add a version number to values, or delete again after a short delay, or use database change events (Change Data Capture (CDC)) to invalidate.
When a primary dies, its replica is promoted in a few seconds, and it already has nearly all the data, because replication is asynchronous but fast. We may lose the last few writes, which is fine for a cache. If there is no replica, about 0.9% of keys miss. The danger is the herd: 8,100 reads/s for those keys hit the database, and every popular key is requested by many callers at once. Single-flight lets one caller per key rebuild it, jitter spreads expiry times, and a circuit breaker and rate limit on the database protect it.
| Failure | What users see | What protects us |
|---|---|---|
| One primary dies | A few seconds of errors or misses for 0.9% of keys | Replica promoted, client retries, short timeouts |
| A whole cache tier is down | Everything is a miss | Circuit breaker, request limit on the database, degraded mode (serve stale or reduced features) |
| Many keys expire together | A spike of misses (avalanche) | Jittered TTLs, staggered warming |
| One popular key expires | Thousands of callers rebuild it (stampede) | Single-flight, or serve stale while one caller refreshes |
| Key that never exists is requested | Every request goes to the database (penetration) | Cache the ‘not found’ answer briefly, or a Bloom filter in front |
value = cache.get(key)
if value is null:
if cache.set(key + ":lock", "1", ttl = 5s, if_absent = true): // only one caller wins
value = db.read(key)
cache.set(key, value, ttl = 300 + jitter)
cache.delete(key + ":lock")
else:
wait briefly, then cache.get(key) // the winner is filling itA simplified model with fixed numbers and no random values. 64 keys with a Zipf-like popularity (key number n gets a share proportional to 1 ÷ n). Each key has a fixed home node from an integer hash. Extra copies of a hot key go on the next nodes in order, as if the key were stored with the suffixes #1, #2 and so on. The 100k ops/s limit and the 100 million key count are illustrative assumptions, not measurements. A real cluster also spreads a node's copies across racks.
| Bottleneck | Fix |
|---|---|
| A hot key saturates one node | Detect with sampling. Serve from a short local cache, keep several copies, or read from replicas. |
| The database is overloaded after a cold start or node loss | Single-flight, jittered TTLs, request limit and circuit breaker, and warm the cache before taking traffic. |
| Connection count (1.1 million in total) | Pool and reuse connections, use a proxy tier to multiplex, and keep client timeouts short. |
| Network bandwidth on a busy node | Compress large values in the client, spread hot keys, and use fewer, larger batches. |
| Memory fragmentation and big keys | Slab classes or a good allocator, defragmentation, a value size cap, and background deletes. |
| Tail latency from batch gets across many nodes | A batch of 100 keys on many nodes waits for the slowest one (about 63% of such batches see a 1-in-100 slow node). Send in parallel, use timeouts, and hedge slow requests. |
| Slot or ring map is out of date on some clients | Version the map, return MOVED redirects, and refresh from the config service on any redirect. |
| Failure | How the design copes |
|---|---|
| A primary node dies | Health check fails, replica is promoted in seconds, the map is updated, and clients follow MOVED. Last few writes may be lost, which is acceptable. |
| A primary and its replica both die | Their slots miss until reassigned. The database absorbs about 0.9% of keys, protected by single-flight and limits. |
| A whole zone is lost | Primaries and replicas are placed in different zones, so replicas take over. Capacity headroom must cover it. |
| A network partition isolates a primary | Clients behind it time out and use the database. The replica side may be promoted, so the old primary must stop accepting writes after a lease ends (to avoid two primaries). |
| The config service is down | Clients keep using their cached map. Only topology changes stop, because the hot path does not need the service. |
| A bad deploy restarts all nodes at once | Roll out a few nodes at a time, drain first, and never restart a primary and its replica together. |
A sharded in-memory cache: 16,384 hash slots over about 110 primaries, each with an async replica, routed by a smart client from a slot map held in a config service. Entries sit in a hash table with approximate LRU eviction and lazy plus sampled expiry. Hot keys are served from a short local cache or from several copies. The application uses cache-aside with delete on write and a TTL on every key, and single-flight, jitter and a circuit breaker keep the database safe when a node is lost.
| Decision | What we gain | What it costs |
|---|---|---|
| A cache, not a store (async replication, no persistence) | Fast, simple, cheap failover. | Data can be lost and reads can be stale, so everything must be rebuildable. |
| Hash slots with a smart client | No extra hop and about 1% of keys move when a node is added. | Clients carry routing logic and must handle redirects and map updates. |
| Approximate LRU by sampling | No list pointers (160 GB saved) and no lock on reads. | Slightly worse eviction than exact LRU. |
| Local cache and copies for hot keys | A hot key stops overloading one node. | Seconds of staleness, extra memory, and more writes for copies. |
| Delete on write plus a TTL | Simple, and wrong data is bounded by the TTL. | A small race can refill a stale value, and the database sees more misses. |
| Single-flight and jitter | A lost node or a popular expiry does not flood the database. | Waiting callers see a little extra latency. |
Show that you know what a cache is, and is not.
Where interviewers check that you know how a cache node really works.
The part where the cache breaks. Know the names and the fixes.
Stale data, races and the questions that change the problem.
A change in requirements is a test of whether you understand why your design looks the way it does.
| New requirement | What changes in the design |
|---|---|
| Strong consistency is required, not just a cache | That is a database. Use a replicated store with a consensus protocol, as in the key-value store design. Keep the cache only for data that can be stale. |
| Multi-region, with a cache in each region | Each region has its own cache, filled from its local database replica. Send invalidations through a stream (database change events) and accept short staleness between regions. |
| The data set is 100 times larger than RAM allows | Add a second tier on fast flash for the warm tail, with RAM for the hot set. Use admission control so rarely used data stays out. |
| Values are very large (video chunks, big objects) | Use a CDN or an object store cache, not RAM. Chunk the values and cache chunks, with a different eviction policy such as size-aware. |
| Hot keys are extremely hot (a viral event) | Switch on local caches with short TTLs for those keys at once, add copies, and put a request coalescing layer in front. Pre-warm the key before an expected event. |
| Writes are much heavier than reads | A cache helps less. Consider write-behind with a buffer, batching, or caching only derived read models. Check whether the cache is worth its cost. |
| Data must survive a cache restart | Add periodic snapshots and an append-only log, and replica warm-up. Accept a slower restart. Or use a store designed for durability. |
| Counters and rate limits live in the cache | Use atomic increments on one node per counter, sub-keys for very hot counters, and short TTLs. Accept that a node loss resets the counters. |
| Area | Weak | Good | Great |
|---|---|---|---|
| Requirements | Starts with ‘use Redis’. Does not ask about staleness or what happens when the cache is down. | Asks about scale, size, staleness and failure behaviour. | States early that it is a cache and not a store, and ties every later choice to that. |
| Estimation | No numbers, or a node count with no basis. | Working set, overhead, node count, ops per node, hit ratio and database load. | Shows that memory sets the size, that a hit-ratio point is worth 9,000 database reads a second, and sizes the cost of adding a node. |
| Partitioning | Hash mod N, or ‘the cache handles it’. | Consistent hashing or slots, and what a new node costs. | Compares slots, rings and proxies, explains MOVED and ASK, and gives the percentage of keys moved. |
| Eviction and memory | ‘LRU’ and nothing more. | Explains LRU, LFU and TTL expiry. | Explains sampled LRU, lazy plus active expiry, fragmentation and why exact LRU costs too much at this size. |
| Hot keys and failure | ‘Add more nodes’, or ignores node failure. | Names stampede, penetration and avalanche, and gives a fix for each. | Detects hot keys, uses L1 and copies with numbers, and protects the database with single-flight, jitter and a breaker. |
| Communication | Lists components without trade-offs. | Follows the seven steps and explains choices. | States the cost of every choice, checks in, and handles curveballs calmly. |
| Mistake | Do this instead |
|---|---|
| Treating the cache as a database, with quorums and durability | Say it is a cache, the database is the truth, and use async replication only for fast failover. |
| Using hash mod N for partitioning | Use slots or consistent hashing, and quote the number: about 1% of keys move, not 99%. |
| Ignoring hot keys | Say that skew, not average load, breaks a node, and describe detection plus a local cache or copies. |
| No plan for a cold or failed cache | Explain single-flight, jittered TTLs, a circuit breaker and a request limit on the database. |
| No TTL on cached entries | Give every key a TTL as a safety net, with jitter, so wrong data cannot live forever. |
| Updating the cache on write instead of deleting | Write the database, then delete the key. Updating needs the right value in two places and races more. |
| Exact LRU with a linked list at huge scale, with no cost estimate | Show the pointer overhead, and use sampling. Mention LFU for scan-heavy loads. |
| Putting the cache in front of everything, including data that is read once | Cache only data with repeat reads, and use admission control so one-off keys do not pollute the cache. |
The ring and slots that stop a new node from flushing the cache.
LRU, LFU and the others, and how to choose.
The exact hash map plus linked list structure, and why sampling replaces it at scale.
Detecting and spreading the keys that overload one node.
Single-flight and stale-while-revalidate in depth.
The other ways a cache fails and how to stop them.
The concept page behind this design.
The durable, replicated cousin: when the data must not be lost.