Asked at
URL Shortener (TinyURL)
Asked from Junior level upFoundations & Storage
Distributed Rate Limiter
Asked from Mid level upAPI Gateway & Security
Distributed Key-Value Store
Asked from Senior level upFoundations & Storage
Distributed Notification Service
Asked from Mid level upMessaging & Queues
Distributed Web Crawler
Asked from Mid level upDistributed Systems
Metrics & Monitoring Platform
Asked from Senior level upObservability & Time-Series
Real-Time Chat App (like WhatsApp or Slack)
Asked from Mid level upReal-Time & WebSockets
Social News Feed (like X/Twitter)
Asked from Mid level upSocial & Feed Systems
Ride-Hailing App (like Uber)
Asked from Senior level upGeospatial & Real-Time
Low-Latency Stock Exchange Matching Engine
Asked from Staff level upFintech & Low Latency
Global Video Streaming Platform (like YouTube or Netflix)
Asked from Senior level upMedia & Streaming
Distributed Hotel & Ticket Reservation System
Asked from Mid level upE-Commerce & Transactions
Shared Document Editor (like Google Docs)
Asked from Staff level upReal-Time & Distributed State
Game Leaderboard
Asked from Junior level upCaching & Data Structures
File Sync Service (Dropbox / Google Drive)
Asked from Mid level upStorage
Payment System
Asked from Senior level upPayments & Transactions
Ad Click Aggregation
Asked from Senior level upStream Processing
AI Support Assistant (RAG)
Asked from Senior level upAI Systems
LLM Inference Platform
Asked from Senior level upAI Systems
Enterprise Semantic Search
Asked from Mid level upAI Systems
AI Code Completion
Asked from Senior level upAI Systems
LLM Gateway
Asked from Senior level upAI Systems
AI Agent That Takes Actions
Asked from Senior level upAI Systems
LLM Evaluation Platform
Asked from Senior level upAI Systems
AI Document Processing Pipeline
Asked from Mid level upAI Systems

Design a Distributed Key-Value Store

Asked from Senior level upDomain: Foundations & Storage
Concepts to know first:

Design a key-value store in the style of Amazon Dynamo and Cassandra. It spreads its data over many servers and keeps working when some of them fail.

An analogy

Think of a key-value store like a giant locker room: every locker has a unique number (the key), and inside is a bag (the value). You can go straight to any locker without searching through all the other lockers.

Where this design ends up. This is version 3 of 3. Part 5 builds it up from version 1 and says why each part was added.
  1. Clients
    • Client app
  2. Services
    • Key-value service
    • Failure detector
  3. Data, outside
    • Storage node A
    • Storage node B
    • Storage node C

1. Requirements and scope

Functional Requirements
  • Put(key, value)
  • Get(key) returns value
  • Configurable tunable consistency (N, R, W)
Non-Functional Requirements & SLAs
  • High availability (AP model)
  • Sub-10ms read/write latency
  • Linear horizontal scalability
Key Traffic Assumptions: Key size: 64 bytes, Value size: up to 1 MB, about 60,000 operations a second (10,000 writes + 50,000 reads), roughly 5 billion a day

2. Back-of-the-envelope numbers

Writes and reads each second
  • Writes: 10,000 writes a second (17%)
  • Reads: 50,000 reads a second (83%)

Read-heavy: about 5 reads for each write. A cache and extra read copies help most here.

Write Throughput
10,000 writes/sec
Read Throughput
50,000 reads/sec
Storage Growth
10TB initial data with 3x replication factor = 30TB raw storage
RAM Cache Footprint
A memtable per node sized to a share of its memory, plus the operating system cache for hot files

3. API

PUT/kv/{key}Store binary value for key
GET/kv/{key}Retrieve value for key

4. Data model and storage

Storage Strategy: LSM-Tree storage engine (SSTable on disk, Memtable in RAM, Write-Ahead Log).
Key: byte array, Value: byte array, Metadata: Vector Clock + Timestamp

5. The design, in three versions

Version 1: Single Node Embedded B-Tree

Single node server with SQLite / LMDB engine.

Distributed Key-Value Store: Version 1: Single Node Embedded B-Tree Version 1 of 3

The picture follows one request through the parts of this version, in order. Under it, switch a part off to see what the request does without it.

One request, step by step

Each numbered arrow is one step. Press "Simulate Request Flow" to follow them one at a time.

Client appKey-value serviceLocal disk file123
  • The order of the steps
  • A request or its reply

The parts: switch one off

1. Clients

Client appreads and writes keys

2. Services

Key-value servicecoordinates one request

3. Data, outside

Local disk filea B-tree on one disk

The steps in words0 of 3 steps shown

  1. Client app to Key-value serviceHTTPS · 3 ms

    The client asks for the key user:42.

  2. Key-value service to Local disk filequery · 8 ms

    One server reads the key from its disk file.

  3. Key-value service to Client appreply · 20 ms

    The value goes back to the client.

Why this version
Fast setup.
Next bottleneck
Single point of failure and bounded by single disk capacity.

Write path, read path and failures

Each path follows one request through the final design (version 3), one hop at a time.

Write pathPut the key user:42

  1. Client
  2. Coordinator node
  3. Hash ring
  4. Storage nodes
  1. Client to Coordinator node

    The client sends PUT user:42 to any node. That node becomes the coordinator for this request.

  2. Coordinator node to Hash ring

    It hashes the key to find the three nodes that hold it (N = 3).

  3. Coordinator node to Storage nodes

    It sends the write to all three. Each node appends it to its write-ahead log, then to its table in memory.

  4. Storage nodes to Coordinator node

    The coordinator waits for 2 of the 3 to confirm (W = 2).

  5. Coordinator node to Client

    It answers success. The third node gets the write a moment later.

Read pathGet the key user:42

  1. Client
  2. Coordinator node
  3. Storage nodes
  1. Client to Coordinator node

    The client sends GET user:42 to any node.

  2. Coordinator node to Storage nodes

    The coordinator asks the three nodes that hold the key.

  3. Storage nodes to Coordinator node

    It waits for 2 answers (R = 2). Because R + W > N, at least one of them has the newest write.

  4. Coordinator node to Client

    It returns the newest version, chosen by version number.

  5. Coordinator node to Storage nodes

    If one node returned an old version, the coordinator sends it the new one. This is called read repair.

What breaks, and what happens then

  • One of the three nodes is down

    What users see
    Reads and writes still succeed, because 2 of 3 is enough.
    What the design does
    The coordinator keeps the missed writes as hints and replays them when the node returns.
  • Two of the three nodes are down

    What users see
    Requests for those keys fail while W = 2 and R = 2.
    What the design does
    A caller that can accept stale data may retry with a weaker setting, such as W = 1.
  • A network break splits the cluster

    What users see
    Both sides may accept writes to the same key.
    What the design does
    Version numbers (vector clocks) show the conflict later. The store keeps both versions and the app merges them.

6. Deep dives

SSTables and LSM Trees
Each write is added to the end of a log on disk, so a crash cannot lose it. It also goes into a sorted table in memory, the memtable. When the memtable is full, it is saved to disk as a new sorted file that is never changed. Now and then, compaction merges these files.

7. Follow-up questions

  • How do nodes detect failure without a central master? (Answer: Decentralized Gossip Protocol heartbeats).

What it costs

Storage is the main bill: three copies turn 10 TB into 30 TB. More copies also mean more network traffic on each write. Compaction uses disk and CPU in the background, so leave room for it.

Another way to design it

A store with one leader per shard is simpler to reason about. Every write for a key goes through one node, so there are no clashing versions to merge. In return, writes for that shard stop while a new leader is chosen.

8. How answers are judged

A passing answer at Mid level. A complete design with numbers: about 10,000 writes and 50,000 reads a second. It explains how keys spread across several servers and goes deep on one part, such as replicas.

How each level is judged
What is judgedJuniorMidSeniorStaff
BreadthHow much of the system does the answer cover?Names the core parts: clients, servers, a database and a cache.Covers the whole main flow, from the request to the stored data and back.Builds a complete design without being led through it.Covers the system, the systems around it and who owns each part.
DepthHow far does it go into the hard parts?Explains what each part does and why it is there.Goes deep on one part, such as the database or the cache.Goes deep on the two or three riskiest parts.Goes deepest where the risk is largest, and explains why the risk is there.
DrivingWho leads the conversation?Follows the interviewer, step by step.Moves forward alone, with an occasional nudge.Leads the conversation from start to finish.Changes the problem when the question asked is not the right one.
Trade-offsAre choices compared and justified?Names more than one option.Says why one option was picked over another.Compares options in detail, with what each one costs.Ties each choice to cost, speed and risk for the business.
Unclear questionsWhat happens when the question is vague?Answers the questions that are asked.Asks questions to make the problem clear.Sets the scope and says what is left out.Questions the assumptions behind the problem itself.
ScopeWhat does it consider beyond the normal path?Covers the normal path, when everything works.Adds what happens when a part fails.Adds growth: what breaks at ten times the load, and the fix.Adds abuse, cost and the daily work of running the system.

Requirements and scope

Strong answer
Before I design, I want to check the scope. This is a Put and Get store with tunable consistency: N replicas, and R and W for how many must answer. I will assume most callers want fast, available writes, but some need R plus W greater than N for an up-to-date read.
Weak answer
Every key gets stored on three servers, and every read and write waits for all three to answer, so the data is always fully consistent.

Shows: Unclear questionsThe difference: The problem asks for configurable N, R and W, not one fixed strict setting for every caller. The strong answer treats it as a per-caller choice.

Estimates

Strong answer
At 10,000 writes and 50,000 reads a second, with a 64-byte key and up to a 1 MB value, storage adds up fast. 10 TB of data needs 30 TB of raw storage once each key is copied to 3 replicas. A 128 GB memtable per node holds recent writes in RAM.
Weak answer
The store holds 10 TB of data, so I would plan for 10 TB of disk in total across the cluster.

Shows: DepthThe difference: 10 TB is the data before copies. With 3 replicas of each key, the cluster needs about 30 TB of raw storage, not 10 TB.

Core design

Strong answer
Put and Get requests hash the key onto a ring of virtual nodes. Each key lands on one server and its next two neighbours going clockwise, giving 3 replicas. Adding or removing a server only moves the keys near it on the ring, not the whole dataset.
Weak answer
I would hash the key modulo the server count to pick which one stores it, then copy it to the next two servers.

Shows: DepthThe difference: Hashing modulo the server count reassigns nearly every key when a server joins or leaves. Consistent hashing on a ring only moves the keys near the change.

Deep dive

Strong answer
The hard part is writes at 10,000 a second without slow disk seeks. A write goes to a log for durability, then an in-memory table sorted by key. Once that table fills, it flushes to disk as an immutable sorted file. A background job then merges old files, so reads do not check too many of them.
Weak answer
Each write goes straight to a row in a normal on-disk table, updated in place, with an index on the key for fast reads.

Shows: DepthThe difference: Updating rows in place means a random disk seek per write, which cannot keep up with 10,000 writes a second. Writing to a log and memory first avoids that.

Failures and trade-offs

Strong answer
If a replica is briefly unreachable, another node holds its writes as a hinted handoff and delivers them once it returns, so writes still succeed. A background repair job also compares replicas and fixes ones that drifted apart. Nodes gossip with each other, not a central master, to first detect a node is down.
Weak answer
If a replica goes down, the coordinator returns an error for any write meant for it, until that replica comes back.

Shows: Trade-offsThe difference: Failing every write for a down replica trades away the availability this design is meant to have. A hinted handoff lets a different node hold the write instead.

We wrote this guide in our own words, informed by public interview guides such as AlgoMaster and Hello Interview. We are not connected to either site. Interviewers differ. The guide and the example answers show the direction each level takes, not a checklist.

10. Check your design with your own AI

Write your design first. Then copy this prompt into the AI chat you already use, and add your design at the end. It asks for a score in each area, one fix for each, and two follow-up questions.

The site sends nothing anywhere. An AI review can be wrong, so check what it says against sections 8 and 9.

See the prompt
You are a system design interviewer. Review my design for the interview problem below.

Problem: Design a Distributed Key-Value Store
Design a key-value store in the style of Amazon Dynamo and Cassandra. It spreads its data over many servers and keeps working when some of them fail.

What users must be able to do:
- Put(key, value)
- Get(key) returns value
- Configurable tunable consistency (N, R, W)

How well it must work:
- High availability (AP model)
- Sub-10ms read/write latency
- Linear horizontal scalability

Numbers to assume:
- Key size: 64 bytes, Value size: up to 1 MB, about 60,000 operations a second (10,000 writes + 50,000 reads), roughly 5 billion a day

Judge my design at the Mid level.
A passing answer at this level: A complete design with numbers: about 10,000 writes and 50,000 reads a second. It explains how keys spread across several servers and goes deep on one part, such as replicas.

For each area below, say whether my design is strong, fine or weak. Give one reason and one fix for each:
1. Requirements and scope
2. Estimates
3. Core design
4. Deep dive
5. Failures and trade-offs

Then ask me the two follow-up questions an interviewer would ask next.
Do not write a full model answer for me.

My design:
[Describe your parts, how one request moves through them, and why you chose each one.]