Skip to content
Tech Atlas, home
Search
Esc
  • All roadmapsBrowse every learning path
  • ExploreFind a technology area
  • ProjectsGuided projects and builds
  • My AtlasYour learning dashboard
Lesson 2 of 6 · Concept · 20 min · revision 1

Multi-leader and leaderless quorums

Compare multi-leader and leaderless replication with a single leader by write path, failover and conflict handling, and run a small simulation that shows why R + W > N alone does not promise the latest value.

Contentsand lesson path

What you will learn

  • Compare synchronous and asynchronous replication and single-leader (read replicas), multi-leader and leaderless topologies by write path, failover behavior and conflict handling.

01. Why it matters

With a single leader, every write in the world travels to one server. Users far from that server pay a long-distance round trip on each write, and while the leader is down, nobody can write until a follower has been promoted.

Two other designs accept writes in more than one place. In multi-leader replication, several leaders each accept writes and exchange them. In leaderless replication, every replica accepts writes and clients talk to several replicas at once. Both remove the single place where every write must go. Both pay with the same currency: two writes to the same data can now happen in two places at the same time, and something has to decide what the result is.

This lesson builds on lesson 01 and compares the three designs by three questions: where does a write go, what happens when a node fails, and how are conflicting writes handled?

02. Multi-leader: fast local writes, conflicts later

In multi-leader replication (also called active–active or multi-primary), each region or data centre has its own leader. A client writes to its local leader, which commits at once and sends the change to the other leaders asynchronously. Writes stay fast, and a region keeps working when its link to the others breaks. The same idea appears in apps that work offline: each phone or laptop acts as a small leader that syncs later.

The cost shows up when two leaders change the same record before they hear from each other:

Diagram: the same row edited in two regions
time  EU leader                            US leader
t1    title := "Q3 plan"    -> commit OK    title := "Q3 budget"  -> commit OK
t2    sends its change  ----------->  <-----------  sends its change
t3    receives "Q3 budget": conflict       receives "Q3 plan": conflict

Both commits succeeded and both users were told so. The conflict is discovered only at t3, after the fact, so it cannot be rejected; it has to be resolved, and every leader must reach the same answer. The common rules are:

  • Last write wins (LWW): keep the version with the latest timestamp and drop the other. It is simple and every leader converges, but it silently throws away a write that was acknowledged, and with clocks that disagree, "latest" may not be the write that really came last.
  • Merge: combine the values when the data allows it, for example the union of two tag sets, or a counter kept as one sub-count per region and summed on read. Data types designed to merge like this are called CRDTs (conflict-free replicated data types).
  • Keep both and ask: store the conflicting versions and let the application or the user choose. CouchDB, for example, picks the same winner on every replica but keeps the losing revisions so that the application can resolve them.

The safest conflict is the one you avoid. Many systems give each record a home: a user's rows are written only through the leader of their home region, so two writes to one record cannot race in normal operation. They still can while the home region is failing over.

Some rules cannot be resolved after the fact at all. A username must be unique, and stock must not go below zero. Two leaders that each check only their own data will both say yes, and no merge rule can undo a promise already made to two users. Such invariants need a single place that decides, such as one designated leader for that kind of write or a strongly consistent service, and those writes pay the cross-region round trip.

Leaders also need a replication topology: who forwards changes to whom. In a ring or a star, one failed leader can stop changes flowing between the others until the topology is repaired. In an all-to-all topology, changes can arrive out of order, so an update may reach a leader before the insert it depends on.

03. Leaderless: quorums of replicas

In leaderless replication, popularised by Amazon's Dynamo paper and used by stores such as Apache Cassandra, there is no leader. Each key is stored on N replicas. A write is sent to all N replicas and counts as successful once W of them acknowledge it. A read asks R replicas and keeps the value with the newest version.

If R + W > N, every set of replicas a read asks shares at least one replica with every set that acknowledged a write. With N = 3, W = 2 and R = 2, any two replicas you read include at least one of the two that took the write. The three numbers are a dial. N = 3, W = 3, R = 1 makes reads cheap, but a write fails whenever one replica is down. W = 1 keeps writes fast and available, but then only R = N guarantees the overlap, so reads become the expensive side.

Replicas that missed writes catch up in three ways: read repair (a read that notices a stale replica writes the newer value back), hinted handoff (another node keeps writes for a replica that is down and delivers them later) and background anti-entropy, which compares replicas with hash trees. Storage internals covers these in depth.

04. Why R + W > N does not promise the latest value

The overlap rule is often taught as "quorum reads always return the latest write". That is not true without further assumptions. Even with R + W > N, a read can return an old or surprising value:

  • A failed write can still be partly there. If a write reaches fewer than W replicas, the client is told it failed, but the replicas that took it are not rolled back. The Cassandra documentation notes that writes are always sent to all replicas, and the consistency level only sets how many answers the coordinator waits for.
  • A write in progress is seen by some readers first. While a write reaches replicas one by one, one reader can see the new value and a later reader the old one. Quorums alone do not make reads linearisable, that is, behave as if there were one copy.
  • Concurrent writes to one key must be ordered somehow. With last-write-wins on clock timestamps, one acknowledged write disappears, and clock skew decides which one.
  • Sloppy quorums, which let substitute nodes accept writes during an outage, break the overlap until hinted handoff delivers those writes.
  • A replica that held the new value can fail and be rebuilt from an older copy, leaving fewer than W replicas with the write.

The script below models the first two cases with three replicas. Each replica stores a version number and a value, and a read keeps the highest version it sees.

Python 3.12 · quorum_sim.py
"""Two ways a quorum read surprises you, with N = 3, W = 2, R = 2. Python 3.12."""

N, W, R = 3, 2, 2
store = {name: (1, 4) for name in 'ABC'}  # replica -> (version, value of x)


def deliver(version: int, value: int, replicas: str) -> None:
    for name in replicas:  # a replica that receives a write keeps it
        store[name] = (version, value)


def read(asked: str) -> int:
    return max(store[name] for name in asked)[1]  # the highest version wins


print('1. A write of x = 5 reaches only A before the coordinator times out')
deliver(2, 5, 'A')
print(f'   the client is told: write failed, 1 of {W} acks')
for asked in ('AB', 'AC', 'BC'):
    print(f'   quorum read from {asked}: x = {read(asked)}')

print('2. A write of x = 6 is on its way: A has it, B and C do not yet')
store = {name: (1, 4) for name in 'ABC'}
deliver(2, 6, 'A')
print(f'   reader 1 asks A and B: x = {read("AB")}')
print(f'   reader 2, a moment later, asks B and C: x = {read("BC")}')
deliver(2, 6, 'B')
print(f'   the write then reaches B and succeeds with {W} acks')
Expected output (python3 quorum_sim.py)
1. A write of x = 5 reaches only A before the coordinator times out
   the client is told: write failed, 1 of 2 acks
   quorum read from AB: x = 5
   quorum read from AC: x = 5
   quorum read from BC: x = 4
2. A write of x = 6 is on its way: A has it, B and C do not yet
   reader 1 asks A and B: x = 6
   reader 2, a moment later, asks B and C: x = 4
   the write then reaches B and succeeds with 2 acks

In case 1 the client believes x is still 4, yet two of the three possible quorum reads return 5. In case 2 reader 2 sees an older value than reader 1, although it read later. Read repair would narrow both windows, but it does not close them. Stores that need stronger guarantees add more machinery, such as version vectors to detect concurrent writes instead of trusting clocks, or a consensus protocol for conditional writes. So treat quorum settings as a statement about likely freshness under stated assumptions, not as a proof.

05. The three designs side by side

Summary: write path, node failure and conflicts
single leader  write: the leader commits, followers replay its log
               leader lost: promote a follower; writes wait until that is done
               conflicts: none between writers, as there is one writer
multi-leader   write: the nearest leader commits, the others receive it later
               leader lost: the other leaders keep accepting writes
               conflicts: concurrent writes in two places; resolve or avoid
leaderless     write: sent to N replicas, successful once W acknowledge
               replica lost: no failover; requests use the replicas that answer
               conflicts: concurrent and partial writes; versions, repair, LWW

These are properties of a configuration, not of a product. Many databases can run in more than one of these modes, and labels such as "CP" or "AP" attached to a brand hide the settings that matter. When you describe a design, name the write path, the acknowledgement rule and the conflict rule.

06. Check your understanding

Practice check · 3 questions

Quorums and multiple leaders

Three questions on partial writes, quorum settings and invariants across leaders.

Q1. A leaderless store has N = 5, W = 3, R = 3. A write of x = 5 reaches replicas A and B, then the coordinator times out and reports a failure. C, D and E still hold x = 4, and no repair has run. What can a quorum read return?
Q2. A team sets N = 3, W = 3, R = 1 so that every read touches one replica only. One of the three replicas goes down for an hour, and the store does not use sloppy quorums. What happens during that hour?
Q3. A social app runs one leader per region with asynchronous multi-leader replication. A username must already be unique worldwide at the moment a user is told it is theirs. Which design achieves that?
Practice only: not graded, not saved, not evidence.

07. Apply it

Extend the replication decision you started in lesson 01:

  1. List the tables or record types that would benefit from writes in more than one region or from offline clients. For each, write the conflict rule (last write wins, merge or keep both) and what a user would see when it applies.
  2. List the invariants that cannot be resolved after the fact, such as uniqueness, balances or stock, and say which single place decides each one.
  3. Change quorum_sim.py to N = 5, W = 3, R = 3 and deliver a write to two replicas only. Print every possible read set with itertools.combinations and count how many return the new value.

08. Review prompt

Without looking back, explain: why multi-leader conflicts are found only after both writes succeed; three ways to resolve them and the cost of last-write-wins; why invariants such as uniqueness need a single decision point; what N, W and R mean and what W = N costs; and at least three reasons why R + W > N does not guarantee that a read returns the latest value.

References

Your progress

Reading state

Sign in to save that you finished reading this lesson.

Sign in to mark reading complete

Prove this skill

8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.
Take the skill check