Design a single-node persistent in-memory cache
Single-Node Persistent In-Memory Cache Design
Design a single-machine in-memory cache for a web service that handles read/write requests. The cache must efficiently store key-value pairs and support standard operations while adhering to strict performance and capacity constraints.
Core Requirements
- In-Memory Storage: Store key/value pairs directly in memory to ensure fast read access.
- Standard Operations: Implement
Get(key),Put(key, value), andDelete(key)operations. - Eviction Policy: Enforce a Least Recently Used (LRU) eviction policy when the cache reaches its configured memory capacity.
- Optional Durability: The design should optionally provide a mechanism for durability, allowing the cache to recover its contents after a process crash or restart.
Expected Deliverables
Candidates are expected to provide:
- A concrete design detailing the chosen data structures.
- Pseudocode-level APIs for the core operations and key internal logic.
- A thorough discussion of concurrency control, including the use of locks, strategies for minimizing critical sections, and approaches to avoid deadlocks.
- Methods for scaling the cache's performance on a single machine, such as sharding or striping to reduce lock contention.
AI interview prep
Core dilemma
Balancing ultra-low latency in-memory operations and high throughput with robust thread safety, efficient memory management, and the complexities of optional single-node persistence/durability.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Design a single-node persistent in-memory cache
Single-Node Persistent In-Memory Cache Design
Design a single-machine in-memory cache for a web service that handles read/write requests. The cache must efficiently store key-value pairs and support standard operations while adhering to strict performance and capacity constraints.
Core Requirements
- In-Memory Storage: Store key/value pairs directly in memory to ensure fast read access.
- Standard Operations: Implement
Get(key),Put(key, value), andDelete(key)operations. - Eviction Policy: Enforce a Least Recently Used (LRU) eviction policy when the cache reaches its configured memory capacity.
- Optional Durability: The design should optionally provide a mechanism for durability, allowing the cache to recover its contents after a process crash or restart.
Expected Deliverables
Candidates are expected to provide:
- A concrete design detailing the chosen data structures.
- Pseudocode-level APIs for the core operations and key internal logic.
- A thorough discussion of concurrency control, including the use of locks, strategies for minimizing critical sections, and approaches to avoid deadlocks.
- Methods for scaling the cache's performance on a single machine, such as sharding or striping to reduce lock contention.