System Design Academy

Saving…

Lesson 8 of 10 in Module 50 of 54 lessons complete

Quorums & Leader Election

Module 5, lesson 8Concept12 min

Definition

Quorum

In plain English
A quorum is the minimum number of copies that must take part in a read or write for it to count.
Think of it like
It is like a club rule that a vote only counts if a majority of members are present.

Leader election

In plain English
Leader election is how a group of machines picks exactly one to coordinate, and picks a new one if it fails.
Think of it like
It is like a team choosing a captain, and a new captain if the old one leaves.

Why it exists

A stock update reaches two copies, but a read asks only the third. The user sees the older stock count.

Overlapping groups help a reader find a completed write. The groups must refer to the same fixed set of replicas.

How it works

N, W and R

In plain English
N is the number of copies, W how many must confirm a write, and R how many are asked on a read.
Think of it like
Like 5 judges, 3 needed to approve, 3 consulted to check.

Split brain

In plain English
Split brain is when two machines both believe they are the leader.
Think of it like
Like two captains giving opposite orders.

Lease and fencing token

In plain English
A lease is a time-limited right to act as leader, and a fencing token is an increasing number that lets storage reject orders from an old leader.
Think of it like
Like a parking permit that expires, stamped with a number so older permits are refused.
  • R + W > N makes every successful read group overlap every successful write group.
  • For N = 3, W = 2 and R = 2, any two read copies share at least one write copy.
  • Overlap alone is not strong consistency: reads must compare versions, and concurrent writes need a consistent ordering rule.
  • The examples assume saved acknowledgements, fixed membership, no substitute replicas, and correctly ordered writes.
SettingRead requirement for overlapMain cost
W = NR = 1Every replica must confirm each write
W = 1R = NEvery replica must answer each read
N = 3, W = 2R = 2One unavailable replica can be tolerated
Majority electionTwo of three; three of fiveA minority cannot elect a leader

A client sends version twelve to three replicas; A and B save and acknowledge it while C is unavailable.

Two saved acknowledgements form a write quorum of three replicas.

A client sends version twelve to three replicas; A and B save and acknowledge it while C is unavailable.

Storage accepts token seven, then token eight from the new leader, and rejects a later write from the old leader with token seven.

Storage must enforce the fencing token.

Storage accepts token seven, then token eight from the new leader, and rejects a later write from the old leader with token seven.

Examples

Read overlapping stock copies

Inventory uses three replicas with W = 2 and R = 2.

Every pair overlaps the completed write pair.
Text
Write saved on: A and B
Possible read groups: A+B, A+C, B+C
Each group includes A or B
Reader compares versions and selects the newest valid value

With one replica down, the remaining two can complete reads and writes. Fresh stock also needs ordered updates and version selection.

Check and reduce the stock in one atomic operation to prevent overselling. Quorum arithmetic alone does not enforce inventory rules.

The insight

R + W > N provides overlap; the protocol must use it correctly.

Trade-offs

Pros

  • Continues through minority failures.
  • Provides overlapping read and write groups.
  • Makes leadership explicit.

Cons

  • Coordination adds delay.
  • A minority cannot elect a leader.
  • Lease timing needs careful assumptions.

Use when

  • Replicated data needs coordinated updates.
  • A shared resource needs one active coordinator.

Avoid when

  • A single node already meets the requirement.
  • Acceptable conflicts make coordination unnecessary.

Quick check

N = 3. Which W and R guarantee reads see the latest write?
Two servers both think they're leader. What is this called?

Takeaways

  • R + W > N guarantees overlap, not a complete consistency protocol.
  • Three-node and five-node majorities tolerate one and two unavailable nodes respectively.
  • Use storage-enforced fencing to reject a former leader’s commands.

Try the quick check above whenever you feel ready.

Previous: Consistency Models