Course contentsShow
← Computer Science
Lesson 2641 of 2,87259. Consensus and ReplicationFree lesson

Multi-Leader Replication

Exploring systems with multiple leaders that can accept writes, and handling concurrent conflicting updates.

Multi-Leader Replication

What you'll learn: How systems coordinate when multiple nodes can accept writes simultaneously, and what happens when those writes conflict.

The Core Idea

In leader-based replication, you learned that one node accepts all writes and replicates them to followers. But what if you had multiple leaders, each capable of accepting writes independently? This is multi-leader replication (also called multi-master replication).

Think of it like having multiple bank branches where you can deposit or withdraw money, rather than one central office. Each branch processes transactions immediately, then syncs with others later. Fast and convenient—but what happens if you withdraw money at two branches simultaneously?

Why Use Multi-Leader?

Multi-leader setups shine in scenarios like:

  • Geographically distributed datacenters: Each datacenter has its own leader, reducing latency for local users
  • Offline-capable applications: Your laptop acts as a leader while disconnected, syncing when reconnected
  • High write throughput: Multiple leaders share the write load

The Conflict Problem

The key challenge: concurrent writes to different leaders can conflict. Unlike single-leader systems where writes are naturally ordered, multi-leader systems must handle situations where two leaders accept incompatible changes before learning about each other.

Example: Leader A sets inventory = 5, Leader B sets inventory = 3 at nearly the same time. When they sync, which wins?

Conflict Resolution Strategies

Systems handle conflicts through:

  • Last-write-wins (using timestamps—but remember clock skew!)
  • Version vectors (tracking causality like vector clocks)
  • Application-level resolution (letting your code decide)
  • CRDTs (data structures designed to merge automatically)

Key Takeaway: Multi-leader replication trades simple consistency guarantees for better availability and performance, requiring explicit strategies to handle concurrent conflicting updates across independent leaders.