Design a Distributed Expiring LRU Cache
Design a partitioned cache with concurrent access, per-entry expiration, and approximate local recency eviction.
Problem statement
Design a cache that supports concurrent get, put, and delete operations, per-entry expiration, and cross-machine key partitioning. Each machine maintains its own local LRU policy; segmented locking may trade exact global recency for concurrent approximate per-segment LRU.
Store expiration timestamps, reject expired values lazily on reads, and run bounded background cleanup. Partition keys with consistent hashing.
For this exercise, assume 100 cache nodes, 10 million operations per second, values up to 1 MB, p99 get latency below 10 ms, replication factor two, and best-effort cache availability during node failure.
Explain ownership, replication, TTL semantics, eviction, hot keys, membership changes, and recovery; the backing data source remains authoritative.
What to build
- Clients can idempotently put, get, and delete bounded key/value entries with a per-entry TTL.
- Expired values are never returned, and each node evicts live entries through a concurrent approximate LRU policy when capacity is full.
- The cluster moves ownership through membership changes without treating cache contents as authoritative data.
At scale
- Source-backed behavior: lazy expiration on get is complemented by periodic background cleanup.
- Source-backed trade-off: segmented locks improve concurrency while making recency exact only within a segment.
- Practice assumption: 100 nodes serve 10 million operations per second with values up to 1 MB and p99 reads below 10 ms.
- Practice assumption: replicate each cache entry to two owners; misses and temporary loss may fall back to the authoritative data source.