System Design Atlas
LOCAL GUEST MODERead and practice without an account.

Your saved topics and reading progress stay in this browser. Sign in to sync supported profile and progress data.

Distributed Key-Value Store (Partition Leaders)

A partition leader loses contact with its followers.

● HardSystem 1117 min3 prerequisites
My progress
Topic tools

Layout updated

Explore the design, then rehearse the decisions without looking.

Problem statement

Design a distributed database that stores small values by key. Clients can look up, write, and delete values. The system should keep data durable, grow across machines, and recover from node failures.

Functional requirements

  • Read, insert, update and delete values by key.
  • Distribute data across partitions and recover from a replica failure.
  • Support strong reads by default, with optional stale reads where clients can tolerate them.

Non-functional requirements

  • Strong per-key reads and durable majority commits within a region.
  • Three replicas in separate availability zones. Keep serving after one zone failure when the other two can communicate.
  • Scale across partitions. Size storage for replica copies, logs, and headroom.

Back-of-the-envelope estimates

Illustrative estimate
1B keys × 1 KB ≈ 1 TB logical values
100k reads/s + 20k writes/s peak
20k writes/s × 1 KB ≈ 20 MB/s of logical write payload

Entities

Entity / logical ownerMinimal authoritative fields and boundary
Record(key, value, version, deleted)Committed per-partition state stored on each replica.
Log entry(term, index, requestId, operation)Ordered replication and durable retry identity.
Partition map(partitionId, replicas, leaderHint, version)Control-plane placement and cached routing hints. Consensus grants leadership.

API design

Operation / inputResponse and retry contract
GET(key)Value or NOT_FOUND. Strong by default. Unavailable when authority cannot be confirmed.
PUT(key, value, requestId)OK after majority commit and apply. Reuse the request ID after an uncertain result.
DELETE(key, requestId)Commit a through the same write path.

High-level design

How to draw this design

  1. Route a keyClient, coordinator, partition router, and
  2. Commit through replicasPartition leader, followers, and durable majority
  3. Store on each replicaReplication , MemTable, , and
  4. Read and recoverLeader read barrier, elections, and replica catch-up

Route a write to the partition leader, replicate it to a durable majority, then apply it and acknowledge.

State ownership
Each partition's replicated log determines committed state. Local files hold the applied data.
Scale
Distribute keys across partitions and spread replicas across zones.
Correctness
Require a durable majority for writes and a read barrier for a current read.
Failure and recovery
Elect a new leader with and catch up lagging replicas before they can take over.

Leader-based partition architecture

Route to one partition per key. Every leader and follower has its own durable replication log and local storage. Follower tails may lag. Control-plane metadata provides routing hints, while consensus determines current leadership.

Leader-based partition architecture
G client->coord 1. GET / PUT / DELETE coord->router 2. Route by key map->router 3. Refresh cached map router->a 4. Choose partition A a->a2 5. Replicate log a->a3 6. Replicate log router->b 7. Choose partition B b->b1 8. Replicate log b->b3 9. Replicate log router->c 10. Choose partition C c->c1 11. Replicate log c->c2 12. Replicate log client Client applications edge coord API gateway / coordinator edge router Partition router compute map Control plane + metadata compute a A leader · AZ 1 state · durable a2 A follower · AZ 2 state · durable a3 A follower · AZ 3 state · durable b B leader · AZ 2 state · durable b1 B follower · AZ 1 state · durable b3 B follower · AZ 3 state · durable c C leader · AZ 3 state · durable c1 C follower · AZ 1 state · durable c2 C follower · AZ 2 state · durable
  • Edge
  • Compute
  • State

━━ Synchronous┄┄ Asynchronous···· Recovery / control▧ Fault

Select a component or follow a numbered connection.

Each arrow is one interaction. Request, background and recovery branches are not one linear transaction.

Read the 12 flow steps

PUT: from request to majority commit

Example with three replicas. A current-term entry can commit once two replicas, including the leader, have durably recorded it. Replay older entries under the consensus protocol’s commit rules.

PUT: from request to majority commit
G put->lead 1. Route key lead->append 2. Assign term and index append->rep 3. Send log entry rep->majority 4. Collect durable replies majority->commit 5. Yes · 2 of 3 commit->apply 6. Apply in order apply->ok 7. Return OK majority->wait 8. No · outcome may be unknown put Client PUT lead Partition leader append Durable leader log append rep Replicate to both followers majority Durable majority? commit Commit entry apply Apply to local state ok Acknowledge client wait Wait or time out

━━ Synchronous┄┄ Asynchronous···· Recovery / control▧ Fault

Select a component or follow a numbered connection.

Each arrow is one interaction. Request, background and recovery branches are not one linear transaction.

Read the 8 flow steps

Inside one replica: log and LSM storage

The consensus log tracks replication and commit. An embedded engine such as RocksDB stores applied state and may keep its own recovery . Both use local storage; the engine alone does not replicate between nodes. GET checks memory before narrowing the disk search.

Inside one replica: log and storage
G wal->apply 1. Commit permits apply apply->mem 2. Buffer applied value mem->sst 3. Flush sorted table get->mem 4. Check newest state first mem->index 5. Search disk if needed index->sst 6. Read candidate blocks sst->compact 7. Merge in background compact->merged 8. Publish merged files wal Durable replication WAL state · durable apply Apply committed entry compute mem MemTable · memory compute get GET after read barrier edge index Bloom filters + index compute sst SSTables · local SSD state · durable compact Background compaction compute merged Merged SSTable levels compute
  • State
  • Compute
  • Edge

━━ Synchronous┄┄ Asynchronous···· Recovery / control▧ Fault

Select a component or follow a numbered connection.

Each arrow is one interaction. Request, background and recovery branches are not one linear transaction.

Read the 8 flow steps

End-to-end flow

  1. PUT: hash the key, route to the leader, durably replicate to a majority, commit, apply locally, then reply.

  2. GET: confirm leadership with a read barrier and wait for the local store to apply that commit point. Then look up the key.

  3. DELETE: commit a through the write path. Reads treat the key as absent.

High-level design component walkthrough

Client / user

Client applications

Client applications

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: GET / PUT / DELETE

Gateway / routing

API gateway / coordinator

gateway / coordinator

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: GET / PUT / DELETE; Route by key

Backend service

Partition router

Partition router

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Route by key; Refresh cached map; Choose partition A; Choose partition B; Choose partition C

Coordination / ownership

Control plane + metadata

+ metadata

Why, tradeoff and connected operations

Durable metadata tracks assignments and distributes router updates. Partition consensus elects leaders. The metadata service stays outside the normal request path.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Refresh cached map

Distributed database

A leader · AZ 1

A leader · 1

Why, tradeoff and connected operations

Each replica stores its own durable consensus log and local state. Local key-value storage fits direct lookups without requiring joins.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Choose partition A; Replicate log; Replicate log

Distributed database

A follower · AZ 2

A follower · 2

Why, tradeoff and connected operations

Each replica stores its own durable consensus log and local state. Local key-value storage fits direct lookups without requiring joins.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Replicate log

Distributed database

A follower · AZ 3

A follower · 3

Why, tradeoff and connected operations

Each replica stores its own durable consensus log and local state. Local key-value storage fits direct lookups without requiring joins.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Replicate log

Distributed database

B leader · AZ 2

B leader · 2

Why, tradeoff and connected operations

Each replica stores its own durable consensus log and local state. Local key-value storage fits direct lookups without requiring joins.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Choose partition B; Replicate log; Replicate log

Distributed database

B follower · AZ 1

B follower · 1

Why, tradeoff and connected operations

Each replica stores its own durable consensus log and local state. Local key-value storage fits direct lookups without requiring joins.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Replicate log

Distributed database

B follower · AZ 3

B follower · 3

Why, tradeoff and connected operations

Each replica stores its own durable consensus log and local state. Local key-value storage fits direct lookups without requiring joins.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Replicate log

Distributed database

C leader · AZ 3

C leader · 3

Why, tradeoff and connected operations

Each replica stores its own durable consensus log and local state. Local key-value storage fits direct lookups without requiring joins.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Choose partition C; Replicate log; Replicate log

Distributed database

C follower · AZ 1

C follower · 1

Why, tradeoff and connected operations

Each replica stores its own durable consensus log and local state. Local key-value storage fits direct lookups without requiring joins.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Replicate log

Distributed database

C follower · AZ 2

C follower · 2

Why, tradeoff and connected operations

Each replica stores its own durable consensus log and local state. Local key-value storage fits direct lookups without requiring joins.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Replicate log

Execution state

Client PUT

Client PUT

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Route key

Execution state

Partition leader

Partition leader

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Route key; Assign term and index

Execution state

Durable leader log append

Durable leader log append

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Assign term and index; Send log entry

Execution state

Replicate to both followers

Replicate to both followers

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Send log entry; Collect durable replies

Execution state

Durable majority?

Durable majority?

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Collect durable replies; Yes · 2 of 3; No · outcome may be unknown

Execution state

Commit entry

Commit entry

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Yes · 2 of 3; Apply in order

Execution state

Apply to local state

Apply to local state

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Apply in order; Return OK

Execution state

Acknowledge client

Acknowledge client

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Return OK

Execution state

Wait or time out

Wait or time out

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: No · outcome may be unknown

Distributed database

Durable replication WAL

Durable replication

Why, tradeoff and connected operations

The durable replication log records ordered mutations before acknowledgement. Recover committed work by replaying from a durable and applied position.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Commit permits apply

Backend service

Apply committed entry

Apply committed entry

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Commit permits apply; Buffer applied value

Backend service

MemTable · memory

MemTable · memory

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Buffer applied value; Flush sorted table; Check newest state first; Search disk if needed

Client / user

GET after read barrier

GET after read barrier

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Check newest state first

Backend service

Bloom filters + index

Bloom filters + index

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Search disk if needed; Read candidate blocks

Distributed database

SSTables · local SSD

· local SSD

Why, tradeoff and connected operations

Immutable sorted files hold durable applied state on SSD. Indexes and Bloom filters reduce work for point reads while merges files in the background.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Flush sorted table; Read candidate blocks; Merge in background

Backend service

Background compaction

Background

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Merge in background; Publish merged files

Backend service

Merged SSTable levels

Merged levels

Why, tradeoff and connected operations

This component owns one step of the request or recovery flow.

Tradeoff: Its capacity and availability affect the operations that depend on it.

Connected operations: Publish merged files

Engineering control room

Deep dives — decisions, failures and recovery

Open a deep dive to follow the steps, try an example and see how recovery works.

Deep dive 1

Partition routing and hot keys

Hash each key to a logical partition and route to its current leader.

Read the explanation and worked example
How it works

Hash customer:42 to partition A. The router reads A’s leader from its cached map.

Walk through an example

If A moves, the old node rejects or redirects the request. The router refreshes its map and retries within the deadline.

Failure and recovery

Move a partition by catching up a new replica and changing membership through consensus. Split hot ranges if traffic comes from many keys.

Why this helps

Many partitions spread independent keys across machines. A cached map keeps metadata lookups off the normal request path.

What you give up

Hashing spreads keys, but one frequently updated key still has a single leader.

Deep dive 2

Majority commit and retries

Acknowledge a write after consensus commits it and the leader applies it.

Read the explanation and worked example
How it works

The leader appends the PUT to its durable replication log and sends it to both followers. One durable follower reply gives it a majority. After commit, the leader applies the update to its local store and replies.

Walk through an example

A client timeout can occur even if the write commits. Retry with the same request ID so the state machine can return the same result.

Failure and recovery

Persist the result with the mutation and retain it for the advertised retry window. Replicate and that state too.

Why this helps

For three replicas, the leader and either follower can durably record the current-term entry.

What you give up

A slow follower is tolerable. A lost majority pauses writes. Cross-zone acknowledgements add latency.

Deep dive 3

Reads and leader failover

Use the leader with a -confirmed read barrier for strong reads.

Read the explanation and worked example
How it works

When the leader loses contact with its followers, it cannot safely serve strong reads. A majority elects an eligible new leader in a higher term.

Walk through an example

The new leader establishes a current-term commit before serving read barriers. An old leader cannot commit new entries without a majority.

Failure and recovery

Refresh routing and catch up lagging followers with log replay or a . Preserve committed entries when truncating uncommitted tails.

Why this helps

The leader verifies current authority and waits until its local state includes the confirmed commit point.

What you give up

An explicitly stale follower read can be cheaper. The default strong read needs a reachable majority.

Deep dive 4

Local storage on each replica

Use a durable replication log and an engine for the applied state.

Read the explanation and worked example
How it works

Apply committed entries to the engine. The MemTable buffers recent writes and flushes immutable . On GET, check memory first, then use Bloom filters and indexes to narrow disk reads.

Walk through an example

A newer hides older values in sorted files. merges tables and removes obsolete versions only when safe.

Failure and recovery

After a crash, recover the engine and resume applying committed entries from a durable applied index. Keep the consensus log until a recoverable covers it.

Why this helps

The log protects ordered mutations before apply. The engine batches applied writes into sorted files.

What you give up

uses disk bandwidth and amplifies writes. Bloom filters save reads but can have false positives.

Deep dive 5

Availability zones and regions

Place three replicas across three zones and keep cross-region recovery optional.

Read the explanation and worked example
How it works

Partition A has a leader in zone 1 and followers in zones 2 and 3. If zone 1 fails, the two remaining replicas can elect a leader.

Walk through an example

If two zones are unreachable, writes and strong reads wait or fail. Surface the loss of and bound retries.

Failure and recovery

For regional promotion, fence the old region and state the recovery point. Track commit latency, replica lag, election rate and backlog.

Why this helps

A local majority can continue after one zone fails. Regional disaster recovery can use an asynchronous copy.

What you give up

An asynchronous regional copy can lose recent acknowledged writes if the whole source region fails.

Tradeoffs and alternatives

DecisionTradeoff / alternative and recovery implication
Partition routing and hot keysHashing spreads keys, but one frequently updated key still has a single leader.
Majority commit and retriesA slow follower is tolerable. A lost majority pauses writes. Cross-zone acknowledgements add latency.
Reads and leader failoverAn explicitly stale follower read can be cheaper. The default strong read needs a reachable majority.
Local storage on each replica uses disk bandwidth and amplifies writes. Bloom filters save reads but can have false positives.
Availability zones and regionsAn asynchronous regional copy can lose recent acknowledged writes if the whole source region fails.

Production scars & failure modes

Failure investigation

A partition leader loses contact with its followers.

Look for: Check the current term, reachability, commit progress and routing errors.

Recovery and invariant: Wait for a majority election. Refresh routes and retry uncertain writes using their original request IDs.

Component / failureImpactRecovery mechanismAlternative / tradeoff
Leader crashesRequests pause during electionElect a new leader via majority and refresh the router.Committed entries survive failover.
Majority unavailableWrites and strong reads stopReject or time out, with bounded retries.Optional stale reads have a weaker contract.
backlogDisk use and latency riseThrottle writes and reserve disk bandwidth for .More headroom costs capacity.

75-second interview summary

I would hash keys to logical partitions. The router caches a placement map and sends each request to the relevant partition leader. Each partition has three durable replicas in separate availability zones.

On a write, the leader appends to its replication log and waits for a durable majority. It commits, applies the operation to its local key-value engine, then replies. For a strong read, it confirms current authority with a read barrier and waits for local apply. If the leader fails, a majority elects a replacement. A timeout can leave the write outcome unknown, so retries reuse the request ID.

Each replica keeps its own and storage. Memory buffers recent applied writes. Sorted files store older entries, and merges them. I would trade some write latency for strong per-key behavior, and explicitly document any stale reads or asynchronous cross-region recovery.

Explain it without looking

Explain partition routing and hot keys

Reveal answer

Hash each key to a logical partition and route to its current leader.

Many partitions spread independent keys across machines. A cached map keeps metadata lookups off the normal request path.

Hashing spreads keys, but one frequently updated key still has a single leader.

Explain majority commit and retries

Reveal answer

Acknowledge a write after consensus commits it and the leader applies it.

For three replicas, the leader and either follower can durably record the current-term entry.

A slow follower is tolerable. A lost majority pauses writes. Cross-zone acknowledgements add latency.

Explain reads and leader failover

Reveal answer

Use the leader with a -confirmed read barrier for strong reads.

The leader verifies current authority and waits until its local state includes the confirmed commit point.

An explicitly stale follower read can be cheaper. The default strong read needs a reachable majority.

Explain local storage on each replica

Reveal answer

Use a durable replication log and an engine for the applied state.

The log protects ordered mutations before apply. The engine batches applied writes into sorted files.

uses disk bandwidth and amplifies writes. Bloom filters save reads but can have false positives.

Explain availability zones and regions

Reveal answer

Place three replicas across three zones and keep cross-region recovery optional.

A local majority can continue after one zone fails. Regional disaster recovery can use an asynchronous copy.

An asynchronous regional copy can lose recent acknowledged writes if the whole source region fails.

Revision checklist

Revision checklist

  • Reconstruct partition routing and hot keys: Hash each key to a logical partition and route to its current leader.
  • Reconstruct majority commit and retries: Acknowledge a write after consensus commits it and the leader applies it.
  • Reconstruct reads and leader failover: Use the leader with a -confirmed read barrier for strong reads.
  • Reconstruct local storage on each replica: Use a durable replication log and an engine for the applied state.
  • Reconstruct availability zones and regions: Place three replicas across three zones and keep cross-region recovery optional.
  • Name the authoritative state, boundary, retry identity and failure-domain durability guarantee.
  • Explain one alternative and exactly which guarantee you would relax.
  • Redraw the request and recovery paths without looking; mark what required a hint.

60-minute interview outline

60-minute interview walkthrough

TimeFocusWhat to cover
0–5 minIntroductionsIntroduce yourself briefly and confirm the interview format.
5–15 minScope and scaleDefine the key-based , scale and strong-read guarantee.
15–30 minHigh-level designDraw the router, and three replicated partitions.
30–45 minDeep divesTrace majority commit, leader failover and the local storage engine.
45–55 minFailure and recoveryExplain retries after timeout, rebuilding replicas and the regional recovery tradeoff.
55–60 minWrap-upSummarize the design and its main tradeoff. Leave time for questions.
On this page
  1. Problem statement
  2. Functional requirements
  3. Non-functional requirements
  4. Back-of-the-envelope estimates
  5. Entities
  6. API design
  7. High-level design
  8. End-to-end flow
  9. High-level design component walkthrough
  10. Engineering control room
  11. Deep dives — decisions, failures and recovery
  12. Tradeoffs and alternatives
  13. Production scars & failure modes
  14. 75-second interview summary
  15. Explain it without looking
  16. Revision checklist
  17. 60-minute interview walkthrough

Save & sync your Atlas progress

Sync your profile and topic progress across browsers, then return to the same study desk.

Google sign-in will appear here after its Azure provider is configured.

Architecture diagram