Scenario
Design a single-machine cache used by a web service to handle read/write requests.
The cache should:
-
Store key/value pairs in memory (fast reads)
-
Support typical operations:
Get(key)
,
Put(key, value)
,
Delete(key)
-
Enforce an eviction policy such as
LRU
when memory capacity is reached
-
Optionally provide
durability
so that after a process crash/restart, the cache can recover its contents
The interviewer expects:
-
A concrete design with data structures
-
Pseudocode-level APIs and key internal logic
-
Discussion of concurrency (locks), minimizing critical sections, avoiding deadlocks
-
How to scale on a single machine (e.g., sharding/striping to reduce lock contention)