Multi-Leader Replication
1. Executive Summary
Multi-leader replication (multi-master, active-active) allows more than one node to accept writes independently. Each leader processes local writes and replicates changes to other leaders asynchronously (typically). The model targets multi-datacenter deployments, offline-first clients, and write locality—users write to the nearest leader without cross-region RTT to a single primary. Kleppmann (DDIA, Chapter 5) identifies multi-leader as powerful but conflict-prone: concurrent writes to the same data item on different leaders produce write conflicts that require detection and resolution.
Unlike primary-secondary, there is no single global serialization point at write time. Leaders may diverge during network partitions; convergence depends on replication topology, conflict detection (version vectors, revision trees), and resolution policy (last-writer-wins, application merge, CRDTs). Production examples include CouchDB/Cloudant replication, Oracle GoldenGate bidirectional replication, LinkedIn's multi-region active-active patterns (with careful conflict design), and mobile sync backends where each device acts as a leader.
This chapter explains topologies (all-to-all, circular, star), conflict causes, async replication lag between leaders, operational complexity, and when multi-leader is justified versus sharded single-leader or leaderless quorums.
2. Why This Topic Matters
Multi-leader replication is seductive in architecture reviews—"write locally everywhere"—but it is the highest-complexity common replication topology. Principal architects must articulate:
- Why conflicts are inevitable under concurrent multi-leader writes, not edge cases.
- How write skew and lost updates differ from single-leader anomalies.
- Circular replication pitfalls (infinite loops, ordering) and topology design.
- Offline clients as logically multi-leader—same conflict math.
Interview failures: proposing multi-master for a workload with global uniqueness constraints; assuming LWW is sufficient; ignoring causal ordering across leaders; or unable to describe conflict resolution ownership (infra vs application). Real outages often trace to misconfigured bidirectional replication or clock-based LWW across regions.
At principal level, interviewers expect you to quantify conflict rate as a design input—not discover it in production. A workload with 0.01% conflicting writes on shared keys may tolerate manual merge; 5% concurrent edits on the same document requires CRDT or single-leader redesign. Multi-leader is as much an organizational commitment (merge UX, support runbooks, schema governance) as a technical topology.
Link multi-leader decisions to the Conflict Resolution chapter early in design reviews—topology without merge policy is an incomplete architecture.
3. Problems Being Solved
| Problem | Multi-leader approach |
|---|---|
| Cross-region write latency | Local leader accepts writes |
| Datacenter outage | Other leaders continue writes |
| Offline mobile editing | Device queues writes; syncs as leader |
| Active-active DR | Both sites writable during normal ops |
| Regulatory data locality | Writes stay in-region; replicate out |
Multi-leader does not eliminate need for coordination on global invariants (unique email, inventory)—those require additional protocols or acceptance of risk.
4. Assumptions and System Model
Assume partial failure, asynchronous inter-leader links, crash-stop leaders:
- Multiple leaders each accept writes from local clients.
- Replication between leaders is typically async—leaders do not wait for global commit.
- Conflicts occur when concurrent updates to same logical object replicate to each other.
- Convergence requires deterministic resolution or application intervention.
Safety (goal): After quiescence and full replication, all leaders agree per resolution policy—not necessarily on intermediate states.
Liveness: Each leader remains writable during partition from peers (availability)—AP tendency during inter-leader partition.
Not assumed: Automatic conflict-free semantics; linearizability without extra coordination.
5. Essential Terminology
| Term | Definition |
|---|---|
| Multi-leader / multi-master | Multiple nodes accept writes. |
| Active-active | All sites writable in normal operation. |
| Write conflict | Concurrent incompatible updates to same item. |
| Replication topology | Graph of leader-to-leader sync paths. |
| All-to-all | Every leader replicates to every other. |
| Circular topology | A→B→C→A chain—ordering hazards. |
| Revision tree | CouchDB-style branching history per document. |
| Vector clock | Detects concurrency across leaders. |
| LWW | Last-writer-wins—timestamp resolution. |
| Offline-first | Client as temporary leader. |
| Anti-entropy | Background sync between leaders. |
| Split-brain (multi-leader) | Divergent concurrent histories—not always fatal if merge exists. |
Mnemonic: Many writers, async mesh, conflicts are normal—design for them.
6. Core Mechanism
Write and replicate loop
- Client writes to local leader L1.
- L1 commits locally; returns ack (fast).
- L1 pushes change to peers {L2, L3, ...} asynchronously.
- Concurrent write on L2 to same key creates conflict when records meet.
- Resolution policy produces converged state (or surfaces conflict to user).
Multi-datacenter topology
Figure 1: Each region has a writable leader; mesh replication propagates changes.
Conflict detection
Figure 2: Concurrent regional writes become conflicts when replication crosses.
Offline client as leader
Figure 3: Mobile offline editing is multi-leader with the device as temporary write leader.
7. Step-by-Step Walkthrough
Scenario: Collaborative calendar; US and EU leaders; async replication; LWW on updated_at.
| Step | Event | State |
|---|---|---|
| 1 | US user moves meeting to 3pm | US leader has v1 |
| 2 | EU user moves same meeting to 4pm | EU leader has v2 |
| 3 | Replication crosses | Conflict—two versions |
| 4 | LWW with EU clock ahead | EU wins—US change lost |
| 5 | US user sees 4pm without notice | Silent data loss |
| 6 | Better: detect siblings | UI prompts merge |
| 7 | Quiescence | Both leaders converge to merged or chosen value |
Insight: Multi-leader without conflict UX is a product failure, not merely a technical edge case.
8. Invariants and Guarantees
| Property | Multi-leader typical |
|---|---|
| Local write availability | High—local leader accepts |
| Global write order | Not total at commit time |
| Conflict freedom | Not guaranteed |
| Eventual convergence | Yes, with resolution policy |
| Linearizability | Not without coordination |
| Uniqueness constraints | Not without global protocol |
Safety: Convergence after quiescence per policy. Liveness: Leaders accept writes during inter-leader partition—divergence grows until heal.
Distinguish formal guarantee (eventual convergence) from implementation choice (LWW vs CRDT).
9. Failure Scenarios
Scenario 1: LWW across regions with clock skew
Setup: NTP drift; EU clock fast.
Effect: EU always wins conflicts—systematic bias.
Mitigation: Logical clocks, version vectors, avoid wall-clock LWW globally.