01

Requirements & scope

Problem Statement & Requirements

Functional Requirements

  • put(key, value) — store a key-value pair
  • get(key) → value — retrieve the value for a given key
  • delete(key) — remove a key-value pair
  • Support variable-size values (1 byte to 1 MB)
  • Keys are strings (up to 256 bytes)
  • Automatic data expiration (TTL support)

Non-Functional Requirements

  • High availability — always writable, even during network partitions (AP system)
  • Low latency — single-digit millisecond reads and writes (p99 < 10 ms)
  • Scalability — horizontally scale to petabytes across thousands of nodes
  • Durability — no data loss once acknowledged
  • Tunable consistency — allow clients to choose between strong and eventual consistency per request
  • Fault tolerance — handle node failures, network partitions, and datacenter outages

Out of Scope

  • Range queries / secondary indexes (that's a full database)
  • Transactions across multiple keys
  • Complex data types (lists, sets, sorted sets — that's Redis)
  • SQL query interface
02

Scale estimations

Scale Estimations

Traffic & Storage

MetricValue
Total key-value pairs10 billion
Average key size64 bytes
Average value size10 KB
Total data size10B × ~10 KB = ~100 TB
Replication factor3
Total storage with replication~300 TB
Reads / second500K RPS
Writes / second100K RPS
Read:Write ratio5:1

Node Sizing

MetricValue
Storage per node2 TB SSD
Nodes needed (data)300 TB / 2 TB = 150 nodes
RAM per node64 GB
Total cluster RAM150 × 64 GB = 9.6 TB
Hot data in memory~10% of data = 10 TB → distributed across nodes

Network

MetricValue
Read bandwidth500K × 10 KB = ~5 GB/s
Write bandwidth100K × 10 KB = ~1 GB/s
Per-node read bandwidth5 GB/s / 150 = ~33 MB/s
Replication bandwidth1 GB/s × 2 (replicas) = ~2 GB/s
03

Layered architecture

Phase 1 of 4 · Client & edge

Start with the entry points

First, define who uses the system and where requests enter. This is the boundary of the design, not yet a complete request path.

Client SDK
Expose simple key-based operations and explicit consistency options.
Architecture after phase 1. Includes Client SDK.
Phase 1 — Start with Client SDK.SVGSVGEditable diagramEditable diagram

This first layer defines the system boundary. The next chapters add application logic and data dependencies. After examining the request paths and tradeoffs, we will add operational safeguards and bring the complete architecture together.

04

API & contracts

Phase 2 of 4 · Application & compute

Add the application logic

Keep the entry points and add the services that do the work. Give each service a clear responsibility before defining its contracts. Storage and background dependencies come next.

Coordinator
Any node can coordinate a request, so the cluster has no single request-routing leader.
Hash ring
Map each key to a stable partition, moving only part of the keyspace when membership changes.
Architecture after phase 2. Includes Client SDK, Coordinator, Hash ring. Client SDK connects to Coordinator. Coordinator connects to Hash ring.
Phase 2 — Added Coordinator, Hash ring. Earlier layers remain in place.SVGSVGEditable diagramEditable diagram

Data Model & API

Wire Protocol

Wire Protocol
Wire ProtocolSVGSVGEditable diagramEditable diagram

Internal Data Format (On Disk)

Internal Data Format (On Disk)
Internal Data Format (On Disk)SVGSVGEditable diagramEditable diagram
05

Data model

Phase 3 of 4 · Data & async work

Connect data and background work

The services now need their dependencies: durable state, fast lookups, or work that continues outside a request. Separate these responsibilities rather than treating every component as a database.

Storage nodes
Append to a durable write-ahead log before acknowledging local writes, then flush sorted tables.
Replicas
Use configurable read and write quorums. Overlapping quorums alone do not guarantee linearizability.
Version resolver
Track concurrent versions and choose an application-appropriate conflict-resolution policy.
Architecture after phase 3. Includes Client SDK, Coordinator, Hash ring, Storage nodes, Replicas, Version resolver. Client SDK connects to Coordinator. Coordinator connects to Hash ring. Hash ring connects to Storage nodes. Storage nodes connects to Replicas. Coordinator connects to Version resolver.
Phase 3 — Added Storage nodes, Replicas, Version resolver. Earlier layers remain in place.SVGSVGEditable diagramEditable diagram

Storage Engine

LSM-Tree (Log-Structured Merge Tree) — Write-Optimized

LSM-Tree (Log-Structured Merge Tree) — Write-Optimized
LSM-Tree (Log-Structured Merge Tree) — Write-OptimizedSVGSVGEditable diagramEditable diagram

Bloom Filters — Avoiding Unnecessary Disk Reads

Bloom Filters — Avoiding Unnecessary Disk Reads
Bloom Filters — Avoiding Unnecessary Disk ReadsSVGSVGEditable diagramEditable diagram

B-Tree vs LSM-Tree Tradeoff

AspectLSM-TreeB-Tree
Write throughput✅ Excellent (sequential I/O)❌ Random I/O for each write
Read latency❌ May check multiple levels✅ O(log N) single lookup
Space amplification❌ Temporary duplicates during compaction✅ In-place updates
Write amplification❌ Data written multiple times (compaction)✅ Written once (usually)
Range queries✅ Data sorted within SSTables✅ Natural ordering
Best forWrite-heavy KV stores (our use case)Read-heavy databases

Our choice: LSM-Tree — write-heavy workload, sequential disk I/O, good for SSDs.

06

Core design decisions

CAP Theorem & Design Philosophy

CAP Theorem & Design Philosophy
CAP Theorem & Design PhilosophySVGSVGEditable diagramEditable diagram

Our choice: AP with tunable consistency

  • Default to availability + partition tolerance
  • Allow clients to request stronger consistency when needed (quorum reads)
  • This is the Dynamo model — write always succeeds, conflicts resolved on read

Core Component: Consistent Hashing

The Problem with Naive Hashing

The Problem with Naive Hashing
The Problem with Naive HashingSVGSVGEditable diagramEditable diagram

Consistent Hashing Solution

Consistent Hashing Solution
Consistent Hashing SolutionSVGSVGEditable diagramEditable diagram

Virtual Nodes (vnodes) — Solving Uneven Distribution

Virtual Nodes (vnodes) — Solving Uneven Distribution
Virtual Nodes (vnodes) — Solving Uneven DistributionSVGSVGEditable diagramEditable diagram

How Many Virtual Nodes?

Nodes in Clustervnodes per NodeTotal Ring PositionsLoad Std Dev
101001,000~5%
501507,500~2%
15020030,000~1%

Tradeoff: More vnodes = better distribution but more metadata to maintain and transfer during rebalancing.

Tunable Consistency (Quorum)

The N, W, R Parameters

The N, W, R Parameters
The N, W, R ParametersSVGSVGEditable diagramEditable diagram

Common Configurations

Common Configurations
Common ConfigurationsSVGSVGEditable diagramEditable diagram

Sloppy Quorum & Hinted Handoff

Sloppy Quorum & Hinted Handoff
Sloppy Quorum & Hinted HandoffSVGSVGEditable diagramEditable diagram
07

Request flows

Detailed Flow Diagrams

Write Flow

Write Flow
Write FlowWide diagram — scroll horizontally.SVGSVGEditable diagramEditable diagram

Read Flow

Read Flow
Read FlowWide diagram — scroll horizontally.SVGSVGEditable diagramEditable diagram

Read Repair

Read Repair
Read RepairSVGSVGEditable diagramEditable diagram
08

Performance & caching

Compaction Strategies

Compaction Strategies
Compaction StrategiesSVGSVGEditable diagramEditable diagram
09

Advanced design

Data Partitioning & Replication

Partition Assignment

Partition Assignment
Partition AssignmentSVGSVGEditable diagramEditable diagram

Replication Strategy

Replication Strategy
Replication StrategySVGSVGEditable diagramEditable diagram

Conflict Resolution

When multiple replicas accept concurrent writes to the same key (during a partition or with W < N), conflicts arise.

Vector Clocks

Vector Clocks
Vector ClocksSVGSVGEditable diagramEditable diagram

Conflict Resolution Strategies

Conflict Resolution Strategies
Conflict Resolution StrategiesSVGSVGEditable diagramEditable diagram

Anti-Entropy: Merkle Trees

For replicas that haven't served reads recently, stale data can go undetected. Merkle trees solve this.

Anti-Entropy: Merkle Trees
Anti-Entropy: Merkle TreesSVGSVGEditable diagramEditable diagram
10

Edge cases

Suppose two replicas accept different values for the same key during a partition. A later read must either resolve the conflict according to a declared rule or return enough version information for the application to resolve it. Now delete that key: the deletion needs a durable marker so an older replica cannot resurrect the value during repair.

11

Tradeoffs

Tradeoffs & Design Decisions Summary

DecisionOption AOption BChosenWhy
CAPCP (strong consistency)AP (high availability)AP (tunable)Write availability is critical; clients can choose consistency level
PartitioningRange-basedConsistent hashingConsistent hashing + vnodesEven distribution, minimal redistribution on scale
ReplicationLeader-basedLeaderless (quorum)LeaderlessNo single point of failure, tunable W/R
Conflict resolutionLWW (simple)Vector clocks (accurate)Vector clocksPreserves concurrent writes, no silent data loss
Storage engineB-TreeLSM-TreeLSM-TreeWrite-heavy workload, sequential I/O
Failure detectionHeartbeat (centralized)Gossip (decentralized)GossipNo single failure detector, scales to thousands of nodes
Anti-entropyFull syncMerkle tree diffMerkle treesO(log N) comparisons, minimal data transfer
CompactionSize-tieredLeveledLeveled (default)Better read performance, lower space amplification
Consistency modelFixed (always strong)Tunable (N/W/R)TunableDifferent use cases need different guarantees
MembershipStatic configDynamic (gossip)Dynamic gossipNodes join/leave without manual config changes
12

Reliability & fault tolerance

Phase 4 of 4 · Operations & resilience

Add operational safeguards

With the request paths and tradeoffs established, add the controls that help detect trouble and keep the system operating. The final diagram retains every layer introduced so far.

Gossip
Distribute membership information without a central bottleneck; failure detection is suspicion, not proof.
Anti-entropy
Compare replica ranges and repair divergence in the background.
Architecture after phase 4. Includes Client SDK, Coordinator, Hash ring, Storage nodes, Replicas, Version resolver, Gossip, Anti-entropy. Client SDK connects to Coordinator. Coordinator connects to Hash ring. Hash ring connects to Storage nodes. Storage nodes connects to Replicas. Coordinator connects to Version resolver. Storage nodes connects to Gossip. Replicas connects to Anti-entropy.
Phase 4 — Added Gossip, Anti-entropy. Earlier layers remain in place.SVGSVGEditable diagramEditable diagram

Failure Detection: Gossip Protocol

Failure Detection: Gossip Protocol
Failure Detection: Gossip ProtocolSVGSVGEditable diagramEditable diagram

Node Join / Leave / Failure Handling

Adding a New Node

Adding a New Node
Adding a New NodeSVGSVGEditable diagramEditable diagram

Handling Node Failure

Handling Node Failure
Handling Node FailureSVGSVGEditable diagramEditable diagram
13

Production architecture

High-Level Architecture

High-Level Architecture
High-Level ArchitectureSVGSVGEditable diagramEditable diagram

Production Architecture

Production Architecture
Production ArchitectureWide diagram — scroll horizontally.SVGSVGEditable diagramEditable diagram
14

Further exploration

Comparison with Real Systems

Comparison with Real Systems
Comparison with Real SystemsSVGSVGEditable diagramEditable diagram
15

Interview playbook

Interview Tips

  1. Start with CAP — "Before diving into the design, let me clarify the consistency model. For a KV store, we usually want AP with tunable consistency." This frames the entire design.

  2. Consistent hashing is the centerpiece — Draw the ring, explain vnodes, show why naive modulo hashing fails. This is the core algorithmic insight.

  3. Walk through a write + read flow — Show how data flows through WAL → MemTable → SSTable, and how quorum reads work. This demonstrates you understand the full data path.

  4. Discuss vector clocks carefully — Use a concrete example with two concurrent writes. Show how conflicts are detected and how the client resolves them.

  5. Mention Merkle trees for anti-entropy — This shows you think about long-term consistency, not just the happy path. "How does a replica that was down for 2 hours catch up?"

  6. Don't forget the storage engine — LSM-Tree with bloom filters is the standard answer. Explain write amplification as a tradeoff.

  7. Gossip protocol for membership — Shows you understand decentralized failure detection. Mention the convergence time (O(log N) rounds).

  8. Name real systems — "This is essentially the Dynamo paper architecture" or "Cassandra uses a similar approach but with LWW instead of vector clocks." Shows you've read the literature.

  9. Tombstones for deletes — A subtle but important point. "You can't just delete from one replica — the other replicas will think the key still exists and resurrect it."