KatInterview

Build a Read-Optimized Geo-Replicated Key-Value Database

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

Last updated

Design a multi-region key-value database tuned for heavy reads, covering storage engine, sharding, replication, consistency, failure handling, hotspots and capacity planning.

You are asked to design a key-value database that runs in several regions around the world and serves a workload dominated by reads. Clients need point lookups, writes, deletes and optional expiry on keys. Multi-key transactions are not required.

Begin by stating your own assumptions (data volume, read/write ratio, value sizes, latency and availability targets, number of regions). Then walk through the design, justifying each decision and naming its costs in performance, complexity and resources.

Cover these eight areas:

  1. Operating-system level performance: threading model (threads vs. async I/O), context-switch cost, memory management and filesystem tuning.
  2. Storage layout and indexing: the on-disk engine, compaction strategy and the write-amplification trade-off.
  3. Partitioning: how keys are distributed, how data is split across nodes, and how the cluster is rebalanced.
  4. Replication and caching: read and write paths, cache coherence, TTLs and invalidation.
  5. Consistency: the model you choose, CAP trade-offs and what guarantees a client actually sees.
  6. Failure handling: failure detection, isolating faults, leader election and recovery.
  7. Overload protection: hot keys, backpressure and rate limiting.
  8. Operations: capacity planning, SLAs/SLOs and observability.

Include a quick back-of-envelope sizing and explain which resource ends up being the bottleneck.

Hints

Hint 1

Start with explicit numbers (keys, bytes, QPS, replicas, regions) and compute both storage-bound and throughput-bound node counts; the larger of the two drives provisioning.

Hint 2

For a read-heavy load with modest writes, think about which engine and compaction style trade extra write cost for cheaper, more predictable reads.

Hint 3

Separate the intra-region story (quorum, strong guarantees) from the cross-region story (asynchronous, conflict resolution), since their latency budgets are very different.