# Key-value store - quorums, and where the consistency knob sits

> How a key finds its replicas, and why choosing how many to wait for buys overlap rather than order. R + W > N guarantees that a read touches at least one…

Source: https://tierslate.com/templates/key-value-store

Infrastructure primitives · System design · deep · 8 step walkthrough · 4 tables

How a key finds its replicas, and why choosing how many to wait for buys overlap rather than order.

**Own this board: 800 credits.** The first act plays on the page. Owned once with credits, never a subscription.

## What this board gets wrong on purpose

The tension: R + W > N guarantees that a read touches at least one replica that saw the write. It does NOT order two concurrent writes, so the coordinator regularly gets two versions back and something has to choose - last-write-wins discards one of them silently and stakes correctness on clocks that are not synchronised, while vector clocks hand the choice to an application that usually has no idea what to do with two shopping carts. Worse, the knob is per REQUEST and not per cluster: one ONE-level read in a hot code path makes the whole store behave as eventually consistent regardless of what operations configured, and nothing in the system reports that it happened. The deletes are the third trap - a tombstone that is garbage collected before a slow replica hears about it lets the deleted row come back.

## Practise this as an interview

Take Key-value store - quorums, and where the consistency knob sits as a timed system design interview on a blank board - on your own, with the requirements to check yourself against, or with a candidate you invite.

## Start here

### Why this design

A distributed key-value store is the question interviewers use to find out whether you understand replication or can only name it. Dynamo, Cassandra and Riak all answer the same three questions - where does a key live, how many copies do you wait for, and who decides when two copies disagree - and the interview probes whether you know that R + W \> N buys overlap rather than ordering, that the consistency level is chosen per request rather than per cluster, and that a delete in a leaderless store is a write. Teams running these stores in production get burned by exactly those three points.

### What you will learn

- How a partition key becomes a token and a preference list of 3 DISTINCT PHYSICAL nodes, with 256 vnodes per machine and rack-aware placement so N = 3 really means three.
- Why W = 2 of N = 3 still sends three writes, and why waiting for the second-fastest replica makes QUORUM both safer and faster than ALL.
- What R + W \> N actually guarantees - overlap, not order - and what last-write-wins and vector clocks each cost when two versions come back.
- Three repair mechanisms at three timescales: hinted handoff for 3 hours, read repair on every read, Merkle-tree anti-entropy as the backstop.
- Why a tombstone needs a 10-day gc_grace, and why a node down longer than that is rebuilt and never rejoined.
- The sizing: 104,000 ops/s at peak and 16 nodes by throughput today, storage-bound at 48 nodes by year five - and the TTL that is worth 34 of them.

### How to read this board

1. Press play once: eight steps follow one put and one read, and the first step is the consistency level, not the coordinator.
2. CALLER · THE KNOB IS HERE, NOT IN THE CLUSTER: the consistency level is a parallelogram because it travels inside the request.
3. COORDINATE · ANY NODE, NO LEADER: the coordinator, the partitioner, and the two diamonds where W and R are counted.
4. THE REPLICA SET · N = 3, NONE OF THEM PRIMARY: three equal replicas, the slow third one in red, and the commit log to SSTable write path.
5. WHEN A REPLICA IS DOWN, then WHEN REPLICAS DISAGREE: two different problems with different machinery - hints and Merkle trees for the first, version reconciliation, read repair and tombstones for the second.
6. Pages 1 to 6 in order: requirements, capacity, storage, availability, how it works, deployment.
7. DATA MODEL: the cluster metadata - keyspaces, cluster_nodes, token_ranges, hinted_writes - because the values themselves are opaque bytes.

## 1 · Requirements

### Ask these before drawing anything

- What is the access pattern - get and put by a single key, or are there range scans and secondary lookups? A store that must answer "all orders for this customer, newest first" is a different design, and bolting a secondary index onto this one is the most common way to ruin it.
- What does a stale read cost? This is the question the whole board turns on. If a stale read is merely annoying, the default can be ONE and the system is fast and cheap. If it is money or a permission, every read pays a quorum.
- Can the application resolve conflicts? Vector clocks are only useful if somebody downstream knows how to merge two versions. If the answer is no, last-write-wins is the honest choice and its cost must be written down rather than avoided.
- How large is a value, and is it ever appended to? Large values and growing values are different failure modes: one blows the row size, the other makes compaction never finish.
- What is the delete volume? Deletes are writes here, and a high-delete workload is the one that turns compaction into the bottleneck.
- Single region or multi? Cross-region quorums cost 80 ms per operation, which usually means the answer is local quorums plus asynchronous replication, which is a weaker guarantee and must be said out loud.

### Functional

- get(key) and put(key, value) on an opaque value, plus delete.
- Tunable consistency per REQUEST, not per cluster: ONE, QUORUM, or ALL.
- Replication factor of 3, configurable per keyspace.
- A node may be added or removed without downtime and without moving more than its share of the token space.
- Survive the loss of any single node with no loss of availability for reads or writes at QUORUM.
- Repair divergence automatically - on read, in the background, and after an outage.

### Non-functional

- p99 of 10 ms for a QUORUM read, 15 ms for a QUORUM write, measured at the coordinator.
- 99.99 percent availability for QUORUM operations, which given N=3 means surviving one replica down per partition and no more.
- Durability: a write acknowledged at QUORUM must survive the immediate loss of any one node. That is a statement about fsync of the commit log, not about replication, and the two are frequently confused.
- Linear scale-out: doubling the nodes doubles the throughput and halves the per-node data, with no rewrite of existing data beyond the moved token ranges.
- No single point of failure and no elected leader on the request path.

### Out of scope, and each of these is a whole other system

- Multi-key transactions. Not supported, not partially supported, and not emulated in the client.
- Secondary indexes. A global secondary index over a partitioned store is a distributed transaction wearing a friendly name.
- Range scans across partitions. The partitioner destroys ordering by design.

## The rest of this board

This page publishes the question. The answer - 5 more written pages, an 8-step narrated walkthrough and a 4-table schema - is the board itself, and it opens in Tierslate.

- 5 written pages
- 8 walkthrough steps
- 4 tables (30 columns)

5 pages behind this one:

- Capacity estimation
- Storage estimation
- Availability
- How it works
- Deployment plan

## Related system design templates

- [URL shortener system design](https://tierslate.com/templates/url-shortener) - Why one tiny write and a hundred cacheable reads make two systems sharing a single table.
- [Distributed cache system design](https://tierslate.com/templates/distributed-cache) - Why a hash ring moves a sliver of keys when a node leaves, and why the hot key and the miss storm remain.
- [Rate limiter system design](https://tierslate.com/templates/rate-limiter) - Why the hard part of limiting requests is where the shared counter lives, not the algorithm.
- [Unique ID generator system design](https://tierslate.com/templates/unique-id-generator) - How 64 bits buy sortable ids with no central counter, and what happens when the clock goes backwards.
- [Web crawler system design](https://tierslate.com/templates/web-crawler) - Why a crawler that feeds on its own output needs politeness, deduplication and loop brakes more than speed.
- [Pastebin system design](https://tierslate.com/templates/pastebin) - Why storing text is the easy part and expiry, abuse and the read path are the design.
- [Load balancer system design](https://tierslate.com/templates/load-balancer) - How requests are spread across servers, and why the health check matters more than the algorithm.
- [API gateway system design](https://tierslate.com/templates/api-gateway) - Why auth, routing and limits move to one front door, and what that door costs when it falls over.
- [Login and sessions system design](https://tierslate.com/templates/login-sessions) - How a password becomes a session, and what changes when the session is a signed token nobody can revoke.
- [Feature flags system design](https://tierslate.com/templates/feature-flags) - Why a flag is evaluated locally from a pushed ruleset, and what a stale ruleset does during an incident.
- [Secrets manager system design](https://tierslate.com/templates/secrets-manager) - How secrets are encrypted under a key nobody holds directly, and why rotation is the feature, not storage.
- [DNS system design](https://tierslate.com/templates/dns-resolver) - How a name becomes an address through layers of caches, and why the TTL decides how fast a mistake spreads.
- [Distributed cron system design](https://tierslate.com/templates/cron-scheduler) - Why a scheduled job needs a lease so it runs once, not once per server, and what a missed tick should do.
- [Background job queue system design](https://tierslate.com/templates/job-queue) - Why a job queue delivers at least once, and how idempotent workers and dead letters keep retries honest.
- [Code execution sandbox system design](https://tierslate.com/templates/code-execution-sandbox) - How untrusted code is run in isolated, time-limited sandboxes, and why the queue in front of them is the real system.
- [Distributed log system design](https://tierslate.com/templates/message-queue) - Why an append-only partitioned log gives ordering and replay, and what replication and consumer offsets cost.
- [Consensus system design](https://tierslate.com/templates/raft-consensus) - How Raft keeps replicas agreeing through elections and a replicated log, and what a network partition really does.
- [Object storage system design](https://tierslate.com/templates/object-storage) - How objects are split, erasure-coded and placed across failure domains so losing disks never loses data.

All 100 system design templates: https://tierslate.com/templates (Markdown: https://tierslate.com/templates.md)
