Consistency by counting
There is a middle path between one leader does everything and replicas drift freely: make reads and writes each check in with several replicas and count responses.
With N replicas, pick two numbers:
- W: a write is confirmed only after W replicas store it
- R: a read asks R replicas and takes the newest answer (using version numbers, as in lesson 7-1)
The magic rule: if W + R > N, any R replicas you read must overlap any W replicas that stored the latest write, so at least one fresh copy is always in your read set. That is a quorum.
With N = 3, the popular setting W = 2, R = 2 gives 2 + 2 > 3: strong-ish reads that also survive one dead replica. Setting W = 1, R = 1 is fastest but 1 + 1 ≤ 3, so stale reads are possible. Consistency becomes a dial, not a switch.
Code exercise · python
Run this quorum checker for the classic N=3, W=2, R=2 configuration.
Code exercise · python
Your turn: check the speed-first configuration N=3, W=1, R=1, printing the same style of report. Predict the verdict before you run it.
Consensus, in one paragraph
One question remains from unit 4: when the leader dies, who picks the new leader? If two nodes each declare themselves leader (a split brain), both accept writes and the data forks.
Consensus protocols like Raft and Paxos solve this with the same counting idea: a node may only become leader after winning votes from a majority of the cluster. Two competing leaders would each need a majority, and two majorities of one cluster always share at least one member, who only votes once. So split brain is arithmetically impossible.
That is why clusters run an odd number of coordinators (3 or 5): majorities stay well defined and one node can die without freezing elections. The deep details fill textbooks, but majority voting prevents split brain is the sentence to carry into interviews.
Quiz
A 5-node cluster using majority voting is split by a partition into a group of 3 and a group of 2. Which group can elect a leader and keep accepting writes?
Problem
A cluster keeps N = 5 copies of each value. Reads are configured to ask R = 2 replicas. What is the smallest W (replicas that must confirm each write) that still guarantees every read sees the latest write?