AlgoViz

Inside a key-value store

medium 24 min

A 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 hearSayBecause
Lookups by one identifier, huge volumeA partitioned key-value storeEvery request names its partition
It must accept writes during failuresLeaderless, N = 3, W = 2 or 1, with repairAny healthy replica can take the write
Read your own writeR + W greater than N, or a fresh read optionThe read and write sets overlap
Exactly one winnerConsensus or a conditional write in a consistent storeQuorums alone do not decide races
One celebrity keyA cache or a split keyMore 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.