Learn System Design
Get Premium
Common Problems
Design a Distributed, In-Memory Cache
Evan King
medium
35 min
Understanding the Problem
Functional Requirements
Core Requirements
- Users should be able to set, get, and delete key-value pairs.
- Users should be able to configure the expiration time for key-value pairs.
- Data should be evicted according to Least Recently Used (LRU) policy.
Below the line (out of scope)
- Users should be able to configure the cache size.
Non-Functional Requirements
At this point in the interview, you should ask the interviewer what sort of scale we are expecting. This will have a big impact on your design, starting with how you define the non-functional requirements.
If I were your interviewer, I would say we need to store up to 1TB of data and expect to handle a peak of up to 100k requests per second.
Core Requirements
- The system should be highly available. Eventual consistency is acceptable.
- The system should support low latency operations (< 10ms for get and set requests).
- The system should be scalable to support the expected 1TB of data and 100k requests per second.
Below the line (out of scope)
- Durability (data persistence across restarts)
- Strong consistency guarantees
- Complex querying capabilities
- Transaction support
The Set Up
Planning the Approach
Defining the Core Entities
The API
High-Level Design
1) Users should be able to set, get, and delete key-value pairs
2) Users should be able to configure the expiration time for key-value pairs
3) Data should be evicted according to LRU policy
Potential Deep Dives
1) How do we ensure our cache is highly available and fault tolerant?
2) How do we ensure our cache is scalable?
3) How can we ensure an even distribution of keys across our nodes?
4) What happens if you have a hot key that is being read from a lot?
5) What happens if you have a hot key that is being written to a lot?
6) How do we ensure our cache is performant?
Tying it all together
What is Expected at Each Level?
Mid-level
Senior
Staff
Schedule a mock interview
Meet with a FAANG senior+ engineer or manager and learn exactly what it takes to get the job.
© 2025 Optick Labs Inc. All rights reserved.