Inside a key-value store
medium 24 minA distributed key-value store keeps simple pairs on many machines.
When it comes up
The moments this idea belongs in a design interview, and the moments it does not.
Signals
When to bring it up
| You hear | Say | Because |
|---|---|---|
| Lookups by one identifier, huge volume | A partitioned key-value store | Every request names its partition |
| It must accept writes during failures | Leaderless, N = 3, W = 2 or 1, with repair | Any healthy replica can take the write |
| Read your own write | R + W greater than N, or a fresh read option | The read and write sets overlap |
| Exactly one winner | Consensus or a conditional write in a consistent store | Quorums alone do not decide races |
| One celebrity key | A cache or a split key | More nodes do not help |
Options
Compare your moves
How do you place keys on 10 nodes that will become 20?
BreaksHash mod 10
- How
- Take the hash of the key modulo the number of nodes.
- Limit
- Going from 10 to 11 moves about 10 of 11 keys.
- Choose when
- The number of nodes never changes.
WorksA ring with one position each
- How
- Consistent hashing, one token for each machine.
- Limit
- Ranges are uneven, and a new node relieves only one neighbour.
- Choose when
- Few nodes, positions chosen by hand.
StrongA ring with virtual nodes, copies in different zones
- How
- Many tokens each; the replica walk skips machines and zones it already has.
- Limit
- More metadata and more ranges to repair.
- Choose when
- Nodes come and go, and hardware differs.