SYSTEM DESIGN SKETCHBOOK / PRACTICE SHEET / NO. 12
Design a distributed key-value store
Internal teams want a shared store for session data, shopping carts and user preferences: put a value under a key, get it back fast, and never be told "unavailable" because one machine died. You are building the store itself, not an application on top of one.
Requirements
- get(key), put(key, value) and delete(key) with values up to 1 MB.
- Spread data across many nodes and add or remove nodes without downtime.
- Keep every value on several nodes in different availability zones.
- Let callers choose, per request, between faster and more consistent reads and writes.
Constraints and assumptions
- 100 TB of data after 3 years; keys up to 256 bytes, values average 2 KB.
- Peak 500,000 reads/s and 100,000 writes/s across the cluster.
- p99 under 10 ms for single-key operations within a region.
- Three availability zones; the store must keep accepting writes if any single zone is cut off or lost.
- Commodity nodes: assume one node can serve roughly 20,000 operations per second and hold about 4 TB comfortably.
Out of scope for the first sketch
Multi-key transactions · Secondary indexes and range queries · Cross-region replication
Draw your design
Rough math and notes
SYSTEM DESIGN SKETCHBOOK / FOLLOW-UPS
Design a distributed key-value store
Finish your first sketch before answering these. Cross out freely.
- One node dies permanently. Which keys lose a replica, and how does the system get back to three copies?
- Two clients write the same key at the same moment on opposite sides of a network partition. What does a later read return?
- A team needs read-your-writes for a user's session. What settings or mechanisms give it, and what does that cost in availability?
- One key starts getting 200,000 reads per second. What happens to its replicas, and what do you do about it?
- You add 20 nodes to a 150-node cluster. How much data moves, and how do you keep the move from hurting latency?
Compare afterwards: worked approaches and reading at sketchbook /questions/key-value-store/review