KatInterview

Design a Sharded Replicated Key-Value Store for 1M Ops/Sec

System DesignModel answer
MediumModel answerSystem Designdistributed-systemskey-value-storereplication

Last updated

Design a distributed key-value database serving 1M ops/sec over 50M records with low tail latency, five-nines availability, tunable consistency and durable acknowledged writes.

Problem

Several microservices in a large platform need a shared store for session context, service state and live counters. Design a distributed NoSQL key-value store that handles heavy read and write traffic with very low latency.

Required operations

  • get(key) returns the value stored under a key.
  • put(key, value) creates or overwrites a value.
  • delete(key) removes a record.

Targets

  • Throughput: 1,000,000 operations per second at peak.
  • Latency (p99): under 5 ms for reads and under 10 ms for writes.
  • Availability: 99.999%, surviving the loss of single nodes and whole racks.
  • Consistency: selectable per request, from eventual to strong.
  • Durability: once a write is acknowledged, it must not be lost.

Sizing assumptions

  • 50,000,000 records in total.
  • Average key is 64 bytes, average value is 1 KB.
  • Peak mix: 800,000 reads/sec (80%) and 200,000 writes/sec (20%).

What to cover in your answer

  1. Capacity estimate: memory, disk, network bandwidth and a node count.
  2. Partitioning and routing: how keys map to nodes, how hot spots are avoided, and how clients find the right node.
  3. Replication and consistency: replica placement, failure handling, and quorum settings (R + W > N).
  4. Single-node storage engine: compare an in-memory hash table, an LSM-tree and a B-tree against the latency and durability goals.
  5. Trade-offs: bandwidth versus consistency versus operational complexity.

Hints

Hint 1

Compute the data size first. It is small enough to fit in RAM several times over, so ask what actually limits the cluster size: CPU and network per node, not capacity.

Hint 2

Count replica-level operations, not client operations. A quorum read touches multiple replicas and every write touches all N, so the per-node load is higher than 1M divided by node count.

Hint 3

Place the N replicas of a key in different racks, and let the client route directly using a cached partition map to avoid an extra proxy hop on the p99 path.

Hint 4

Define 'acknowledged' precisely: persisted in a write-ahead log on W replicas. Group commit lets you do that without one fsync per write.