Stage 4 · Provision
Data Systems at Scale
Replication Topologies
Leader-follower, multi-leader, and quorum replication with failover tradeoffs.
Why Replicate?
Replication copies data across multiple nodes for three reasons: availability (survive node failures), read scalability (serve reads from replicas), and latency (serve reads from geographically close replicas). The topology determines how data flows between nodes.
Leader-Follower
Leader-follower (primary-replica) is the most common replication topology. The leader handles all writes. Followers replicate from the leader and serve reads. This provides strong consistency for reads from the leader and eventual consistency from followers.
Leader (Primary)
│
├── async replication ──► Follower 1 (us-east-1)
│ └── serves read queries
│
├── async replication ──► Follower 2 (us-west-2)
│ └── serves read queries
│
└── async replication ──► Follower 3 (eu-west-1)
└── serves read queries
Writes ──► Leader only
Reads ──► Followers (eventual consistency)The leader handles all writes and replicates to followers asynchronously. Followers serve read traffic. If the leader fails, a follower is promoted.
Multi-Leader Replication
Multi-leader replication allows writes at multiple nodes. Each node is a leader that can accept writes and replicate to other leaders. This is useful for multi-datacenter deployments where each datacenter needs local write performance.
Leader A (us-east-1) ◄──► Leader B (eu-west-1)
│ │
└── replication ──►┘ └── replication ──►┘
Writes at A replicate to B (and vice versa)
Conflict resolution required when same key written at bothMulti-leader replication provides write availability across regions but introduces conflict resolution complexity. CRDTs or last-write-wins are common strategies.
When the same key is written at two leaders simultaneously, you must resolve the conflict. Last-write-wins loses data. CRDTs work for specific data types. Custom merge logic is error-prone. Avoid multi-leader unless you have a clear need.
Quorum Replication
Quorum replication requires a minimum number of nodes to acknowledge a write (write quorum) or serve a read (read quorum). The formula W + R > N guarantees reading the latest write. This balances consistency with availability.
N = 5 # Total replicas
# Strong consistency: W=5, R=1
# All replicas must acknowledge writes, any replica can serve reads
# High write latency, low read latency
# Balanced: W=3, R=3
# Quorum writes, quorum reads
# Moderate latency for both
# High availability: W=1, R=5
# Any replica can accept writes, all replicas must agree on reads
# Low write latency, high read latency
# Eventual consistency: W=1, R=1
# Any replica for both — fastest, least consistentTune W and R based on your consistency and latency requirements. Higher W means stronger consistency for writes. Higher R means stronger consistency for reads.
Replication Lag
Replication lag is the delay between a write at the leader and its appearance at a follower. Lag ranges from sub-milliseconds (synchronous) to seconds (async). During high load, lag can spike. Clients reading from followers may see stale data.
- Read-after-write consistency — Route reads to the leader after a write.
- Monotonic reads — Ensure a client always reads from the same or newer replica.
- Bounded staleness — Read from a follower only if lag is below a threshold.
- Causal consistency — Order reads based on causal relationships.
Choosing a Topology
| Topology | Consistency | Write Availability | Complexity |
|---|---|---|---|
| Leader-Follower | Strong (from leader) | Single leader | Low |
| Multi-Leader | Eventual | Multiple leaders | High |
| Quorum | Tunable | Quorum-based | Medium |
| Leaderless | Tunable | All nodes | Medium |
Leader-follower is the simplest and most battle-tested topology. Use it unless you have a specific requirement for multi-leader (multi-datacenter writes) or leaderless (maximum availability) replication.
Mark this lesson complete to store local progress and unlock a cleaner resume path the next time you visit.