Design a Distributed Cache with an Index Database
Keep a durable key index consistent with evictable cached blobs through concurrent updates, expiry, and cache-node failure.
Problem statement
For this exercise, assume clients store and retrieve bounded opaque blobs by key through a distributed caching service. Index metadata belongs in a durable database; blob bytes live only in the distributed cache and may disappear through eviction or node failure.
The cache is an accelerator, not durable blob storage: a previously acknowledged put may later return a cache miss. Support conditional replacement and deletion, per-entry expiry, and retry-safe writes.
A read begun after an acknowledged replacement or deletion must not return the older blob version; an overlapping read may use the index version it observed. Never return an expired blob or bytes belonging to another key or version.
A missing blob behind a live index entry is a miss that the service must detect and reconcile safely; it must never be mistaken for a successful value or delete a newer index version. The design should explain metadata authority, cache placement, publication ordering, eviction, overload, and recovery.
Assume one region and authenticated clients. Backing-origin reconstruction, durable preservation of every blob, search over blob contents, and multi-region writes are outside scope.
What to build
- Clients can put a blob with an expiry, retry the same logical write, and conditionally replace a key using its index revision.
- Clients can get a non-expired blob matching the observed current index version, or receive a truthful miss or dependency-unavailable result.
- Clients can conditionally delete a key, while the service detects expired or missing cache blobs and repairs stale index references without removing newer writes.
At scale
- For this exercise, assume up to 100 million live index entries, 200,000 gets per second, and 20,000 puts or deletes per second in one region; hot keys may receive a disproportionate share of reads.
- Assume blobs are at most 1 MB and the cache has a fixed byte budget smaller than the total bytes ever written; expiration and eviction are routine outcomes rather than exceptional data loss.
- Target p99 cache-hit reads below 20 milliseconds and 99.9% service availability; return bounded unavailable responses when index authority cannot be consulted safely.
- After an acknowledged replacement or deletion, later-started reads must not return the previous version; expired entries are never values, while evicted live entries may become explicit misses.