AlgoViz

Inside a key-value store

medium 24 min

A distributed key-value store keeps simple pairs on many machines.

Remember it

The few things worth knowing cold, and how to make them stick.

Memory hook

Key, hash, ring position, N replicas.

A street where every house keeps the spare keys of the two houses before it.

Cheat sheet

Common replication factor
N = 3
Overlap rule
R + W greater than N
Balanced
N = 3, W = 2, R = 2
Keys moved by a join
about K / (N + 1)
Cassandra tokens for a node
16 by default
DynamoDB item limit
400 KB
DynamoDB latency
single-digit milliseconds, says AWS

Spot it when you see

  • Every request names one key.
  • The data or traffic outgrows one machine.
  • Writes must be accepted during failures.

Tricks that stick

  • CHURN: Consistent hashing (partitioning), High availability (replication), Uniform distribution (virtual nodes), Read and write quorum (tuning), N replicas (fault tolerance).
  • Send to N, wait for W.
  • The coordinator is a role, not a machine.

Do not forget

  • Two copies on one machine because of virtual nodes.
  • Calling quorum overlap linearizable.
  • Retrying increments after a timeout.
  • Sizing for storage and forgetting the peak load.