Quick revision
The short answer
The API is get, put with an optional expected version, delete and an optional TTL, with values capped at about 1 MB. Keys are placed with consistent hashing and virtual nodes, so a joining node moves only nearby ranges, and a partition map kept by a coordination service or spread by gossip says where each key lives. Each key is stored on N = 3 replicas in different zones; a write waits for W acknowledgements and a read for R, and with R + W > N every read overlaps the latest acknowledged write. 50 TB times 3 is 150 TB, roughly 100 nodes, each running a log-structured engine.
What to remember
In this answer, we designed a key-value store with a small API of get, put with an optional expected version, delete and TTL, and a capped value size. We sized it at 150 TB of replicated data across about 100 nodes at around 30,000 operations per second each. Consistent hashing with virtual nodes places keys so that membership changes move only nearby ranges, tracked in a partition map. Three replicas in different zones with quorums of W and R, where R + W > N, make reads overlap the latest acknowledged write, and each node stores data in a log-structured engine with a commit log, memtable, sorted files and background compaction.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
The API is get, put with an optional expected version, delete and an optional TTL, with values capped at about 1 MB. Keys are placed with consistent hashing and virtual nodes, so a joining node moves only nearby ranges, and a partition map kept by a coordination service or spread by gossip says where each key lives. Each key is stored on N = 3 replicas in different zones; a write waits for W acknowledgements and a read for R, and with R + W > N every read overlaps the latest acknowledged write. 50 TB times 3 is 150 TB, roughly 100 nodes, each running a log-structured engine.
Why this question is asked
A distributed key-value store is the building block under caches, session stores, feature flags and much of the modern data stack, and designing one touches every classic trade-off: partitioning, replication and consistency. Interviewers ask it to see whether we can explain these mechanisms simply and attach numbers to them. In this answer, we will define the API, size the cluster, place keys with consistent hashing, replicate them with quorums, explain what a client sees when it reads after a write, and look inside each node's storage engine.
1The API and Its Limits
The interface is deliberately small. A client can read a key, write a value, delete it, and optionally give it a time to live (TTL) after which it expires. Every value carries a version, and put can take an expected version so a client can say 'only write if nobody changed it since I read it'.
Capping the value size, for example at 1 MB, keeps every request small and predictable: a single huge value would block a connection, stretch tail latency for everyone, and make replication and compaction uneven. Large blobs belong in object storage, with the key-value store holding a pointer.
2Sizing the Cluster
We hold 50 TB of data and serve 1 million operations per second. With three replicas, the raw data is 50 x 3 = 150 TB. A node with, say, 4 TB of disk should not be filled beyond about half, because the storage engine needs free space for compaction and the cluster needs room to grow, so we count about 2 TB usable per node. That gives 150 / 2 = 75 nodes, and with headroom for failures and growth, roughly 100 nodes.
Spread over 100 nodes, 1 million client operations per second is 10,000 per node. But each write is applied on three replicas and each quorum read touches two or three, so each node handles around 30,000 operations per second including replication traffic. That is comfortable for a modern server with SSDs, which tells us the design is limited by capacity more than by throughput.
3Placing Keys With Consistent Hashing
The simplest placement, node = hash(key) mod number_of_nodes, breaks when the cluster changes: going from 100 to 101 nodes would move almost every key. Consistent hashing avoids that. Imagine the hash space as a ring from 0 to 2^64. Each node owns points on the ring, and a key belongs to the first node clockwise from the key's hash. When a node joins, it takes over only the ranges just before its points, and every other key stays where it was.
With one point per node, ranges are uneven and a new node relieves only one neighbour. So each physical node owns many points, called virtual nodes or vnodes, for example 128 or 256. Its ranges are then scattered around the ring, load evens out, and a joining node takes a small slice from many nodes at once. Where each range lives is recorded in a partition map, kept in a coordination service such as etcd or ZooKeeper or spread between nodes by gossip, a protocol in which nodes regularly exchange state with random peers. Clients or coordinator nodes use the map to send each request to the right replicas.
| Ring range (hash) | Primary | Replicas 2 and 3 |
|---|---|---|
| 0x00.. to 0x0a.. | node 17 (vnode 3) | node 52, node 88 |
| 0x0a.. to 0x13.. | node 4 (vnode 91) | node 17, node 63 |
| 0x13.. to 0x1f.. | node 52 (vnode 40) | node 88, node 4 |
| key 'user:42:cart' hashes to 0x0c.. | node 4 | node 17, node 63 |
4Replication and Quorums
Each key is stored on N replicas, usually 3, placed in different racks or availability zones so one failure cannot take out all copies. A coordinator, the node or client library that handles a request, sends a write to all three replicas but waits for only W acknowledgements before telling the client it succeeded. A read asks R replicas and returns the value with the newest version.
The rule to remember is R + W > N. With N = 3, W = 2 and R = 2, any two replicas you read must include at least one of the two that acknowledged the latest write, because there are only three replicas and 2 + 2 = 4 > 3. So every read overlaps the latest acknowledged write and returns it. If we choose W = 1 and R = 1 for speed, R + W = 2 is not greater than 3, and a read may hit a replica that has not received the write yet.
11 messages in order. Play them, or step through them one at a time.
Any two replicas overlap the two that acknowledged, so the newest version is always seen.
5What a Client Sees When It Reads After a Write
With R + W > N, a client that reads after its write completes sees that write or a newer one, as long as the quorum members are reachable. The slower replica, C above, catches up in the background: the coordinator can send it the newest value when it notices the stale copy during a read, which is called read repair, and replicas periodically compare their data with Merkle trees, hash trees that pinpoint which ranges differ, to fix anything missed.
If we relax to R = 1 for lower latency, the store becomes eventually consistent: a read may briefly return an older value, and all replicas converge soon after. Many stores let each request choose its level, so a shopping cart read can be fast while a balance check uses a quorum. Note that quorums give overlap, not atomic read-modify-write; two clients updating the same key at once still need the expected-version check from the API.
6Inside Each Node: A Log-Structured Engine
Each node stores its keys with a log-structured merge tree (LSM tree), the engine behind stores like Cassandra, RocksDB and ScyllaDB. A write is first appended to a commit log on disk, a sequential write that makes it durable, and then placed in an in-memory sorted table called the memtable. When the memtable fills, perhaps at 64 MB, it is flushed to disk as an immutable sorted file, an SSTable.
Reads check the memtable and then the SSTables from newest to oldest, using small Bloom filters to skip files that cannot contain the key. In the background, compaction merges SSTables, keeping only the newest version of each key and dropping deleted ones, so reads stay fast and space is reclaimed. Everything on disk is written sequentially, which is why LSM engines sustain very high write rates.
- Commit logappend-only, makes the write durable
- Memtablein-memory sorted table, serves recent reads
- SSTables on diskimmutable sorted files flushed from memory
- Compactionmerges files, drops old versions and tombstones
4 layers, from the top down. Step through them one at a time.
7Follow-up questions
What happens when a replica is down during a write?
The write still succeeds if W replicas acknowledge. Many stores also keep a hint, a note on another node with the missed write, and replay it when the replica returns, called hinted handoff; anti-entropy repair with Merkle trees fixes anything that hints missed.
How do you handle a hot key that one node cannot serve?
Cache it in front of the store, add read replicas for that key, or change the key design, for example splitting a counter into several sub-keys and summing them on read.
Why use a coordination service rather than only gossip?
A coordination service like etcd gives one authoritative, consistent partition map, which is simpler to reason about during changes. Gossip avoids a central dependency and scales well. Both work; leaderless stores in the Dynamo family use gossip, while range-partitioned stores often keep their map in a consensus-backed service.
8Conclusion
In this answer, we designed a key-value store with a small API of get, put with an optional expected version, delete and TTL, and a capped value size. We sized it at 150 TB of replicated data across about 100 nodes at around 30,000 operations per second each. Consistent hashing with virtual nodes places keys so that membership changes move only nearby ranges, tracked in a partition map. Three replicas in different zones with quorums of W and R, where R + W > N, make reads overlap the latest acknowledged write, and each node stores data in a log-structured engine with a commit log, memtable, sorted files and background compaction.
Open with
The API is get, put with an optional expected version for compare-and-set, delete, and optionally a TTL, and I would cap values at about 1 MB so requests stay small and predictable.
Then, if they want more
For sizing, 50 TB times three replicas is 150 TB; at about 2 TB usable per node with headroom that is roughly 100 nodes, each doing around 30,000 operations per second including replication.
To place keys I use consistent hashing with virtual nodes: each node owns many points on a hash ring, so keys spread evenly and a joining or leaving node only moves nearby ranges. A partition map, kept in a coordination service like etcd or spread by gossip, tells clients or coordinators where each key lives.
Each key goes to N replicas, usually 3, in different racks or zones. A write waits for W acknowledgements and a read for R, and if R plus W is greater than N, say 2 and 2 with N of 3, every read overlaps the latest acknowledged write, so a client reading after its write sees it.
With smaller quorums it is eventually consistent, with read repair and anti-entropy catching replicas up. On each node I would use a log-structured engine: an append-only commit log for durability, an in-memory table, and sorted files flushed to disk and compacted in the background.
About this answer
- Last updated
- 13 November 2026
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Design the API and the main mechanisms of a distributed key-value store that holds 50 TB...": https://scrivio-interview-library.netlify.app/architecture/system-design-problems/9aca94c714/