Loading...

A 20-minute mock system design interview. You drive the pace. Jump to the board when you are ready; skip capacity math if you want. The interviewer grades your thinking, not a template match.
The API is two calls, so there is almost no product to negotiate. The signal sits in the machinery: how keys spread across machines, how copies stay in step, what a read returns when copies disagree, and what the cluster does while a node is dead. "Consistent hashing plus replication" is a phrase, not a design.
Two shared surfaces (only one is on screen at a time; use the panel arrow to switch):
Build incrementally while you talk. Trace one put and one get end to end through your diagram, including the write that lands while one replica is down. Argue the tradeoff, not "that's what Cassandra does."
Read this before you go in. These are the decisions, and why they matter.
Everything downstream depends on it. Must every read see the latest write, is "eventually" fine, or should each caller choose? Then the read and write mix, value size (kilobytes or megabytes), point lookups versus range scans, and one region versus several. A strong default: point lookups, small values, always writable, consistency tunable per request, one region across three zones.
hash(key) mod N sends nearly every key somewhere new when N changes, and N will change. Put nodes and keys on a hash ring instead: a key belongs to the first node clockwise, and a new node takes over only the slice next to it, roughly one Nth of the data. Give each machine many ring positions (virtual nodes) so slices even out, bigger machines carry more, and a dead machine's load spreads over many survivors rather than one neighbour. Interviewers will ask what goes wrong without them.
Store each key on N machines (usually three): walk clockwise from the key and take the first N distinct physical machines, skipping virtual nodes you already used, and ideally skipping until the copies land in different racks or zones. There is no leader: the node that receives a request acts as coordinator, finds the replicas and fans out. Expect "why no leader?" Answer: no single point of failure and the store stays writable, at the price of replicas that can disagree.
W is how many replicas must confirm a write; R is how many must answer a read. When W + R > N, any write set and any read set share a replica, so a read reaches the latest acknowledged write. N = 3 with W = 2, R = 2 is the balanced default. W = 3, R = 1 favours reads; W = 1, R = 3 favours writes; W = 1, R = 1 gives up the overlap for speed. Make the numbers per request, and say the cost: the coordinator waits for the slowest of the replicas it needs. Strong candidates add the caveat that overlap is not linearizability: concurrent writes, partial failures and sloppy quorums can still surface stale or duplicate versions.
Without a leader, two clients can update one key through different coordinators during a network blip. Last-write-wins keeps the newest timestamp: simple, but the other write vanishes silently and clocks drift. Good for caches and "last seen" fields. Vector clocks attach a counter per node to each version. If one clock is ahead or equal on every counter, it replaces the other; if each is ahead somewhere, the versions are concurrent siblings and the reader's application merges them (a cart takes the union). Costs: merge logic in the client, deleted items that come back after a union, clocks that grow and need trimming. CRDTs are the "data types that merge themselves" variant.
All-to-all heartbeats cost about n² messages per round. With gossip, each node bumps its own heartbeat counter and swaps its membership list with a few random peers every second; a peer whose counter stops rising past a timeout is suspected down, and more than one node must agree before the cluster acts on it.
For a write-heavy store, an LSM tree: append to a commit log for durability, insert into a sorted in-memory memtable, acknowledge; flush full memtables as immutable SSTables, and compact them in the background. Reads check the memtable, then each SSTable's Bloom filter (never a false "no"; about one false "maybe" in a hundred at ten bits per key), then open only the files that might hold the key. Deletes write tombstones that must reach every replica before compaction drops them, or a deleted key can come back. A B-tree updates in place: steadier reads, more random writes.
One complete design you can study, then rebuild in your own words. Do not recite it. In the interview, draw your graph and defend the choices.
get(key), put(key, value), delete(key); values under about 10 KB; point lookups onlyHow the graph works: callers use a client library that knows the ring (or go through a load balancer to any node). Every storage node is identical: it holds a slice of the ring, can coordinate any request, gossips membership, and runs the storage engine locally. A background repair worker compares Merkle trees between replicas.
Web Client / Service (callers, ring-aware client library)
→ Load Balancer (optional: any node can take any request)
→ Storage Node tier (Service labelled "Storage node"; mark distributed)
↔ other Storage Nodes: replicate to N = 3 (label the edge), gossip membership (label)
· Note: "Ring: consistent hashing, 256 vnodes/machine or fewer, N = 3, W = 2, R = 2"
· Note: "Engine: commit log → memtable → SSTables + Bloom filters, compaction"
← Worker: anti-entropy repair (Merkle trees), on a schedule
→ Blob Store (optional: snapshots and backups)
cart:42 onto the ring and sends the put to the nearest node, which becomes the coordinator.The read: get("cart:42") with R = 2 asks two replicas, compares versions, returns the newest (or both siblings if their clocks are concurrent) and repairs any stale replica on the way out.
key → [ (value, vector clock [node:counter,…], timestamp, tombstone?) … siblings ]
ring state: node → (tokens, zone, status, heartbeat) — gossiped, every node holds it
hints: (target node, key, version, value) — kept by stand-ins until delivered
A leader per partition with Raft or Multi-Paxos (the way DynamoDB, Spanner and CockroachDB work) if the caller needs strong consistency and can tolerate a short pause on failover. Last-write-wins instead of vector clocks for data where losing a concurrent write is harmless. A B-tree engine for read-heavy workloads with range scans. What matters is that you can argue the tradeoff.