Module 25 / 46 · Phase E — Distributed Reality · finale · 45 min

Replication
patterns.

Raft solved the consensus problem for one shape of replication: single-leader. But there are three canonical shapes — and most production systems use whichever one matches their workload best. Time to map the whole landscape.

// What you'll know by the end

  • The three main replication topologies
  • Sync vs async vs semi-sync trade-offs
  • How real systems handle conflicts at scale
  • Which pattern fits which workload
§ 01 — Why we replicate at all

More copies.
More questions.

Every distributed system replicates data. There's no way around it — a single copy of anything is a single point of failure, and storing only one copy makes the system unavailable the instant that machine hiccups. Replication isn't optional. But the moment you have multiple copies, you've signed up for a new set of problems: keeping them in sync, deciding where reads come from, handling the cases where they disagree. Raft (M.24) solved one specific version of this. Now we widen the lens.

// THE FOUR REASONS YOU REPLICATE
Durability
If one node dies, others still have the data. Disk failures, fires, deletions — having N copies means tolerating N-1 losses. This is the simplest reason and the foundation everything else builds on.
Availability
If one node is unreachable, others can still serve requests. A replicated system can be configured to remain available through machine failures, network partitions, and zone outages — depending on the pattern and quorum settings.
Latency
Read from the geographically closest copy. A user in Tokyo reading from a Tokyo replica avoids the 150ms RTT to Virginia. Replication for latency is what powers global products feeling instant everywhere.
Read scale
Spread reads across many replicas. If your workload is 100:1 read-heavy (like M.17's URL shortener), replicas multiply your read capacity linearly. Writes still bottleneck at the leader; reads scale out.

The cost of all this is the same one we've been circling for the whole phase: multiple copies means multiple sources of truth, and they can disagree. CAP (M.21) tells you that disagreement is inevitable during partitions. Consistency models (M.22) tell you how disagreement is allowed to manifest. Lamport clocks (M.23) tell you how to track causality across copies. Consensus (M.24) tells you how copies can agree on a total order. This module is where the four come together — it surveys the actual shapes of replication that real systems deploy and shows you how to pick.

Three shapes. Three trade-offs. The same data, three completely different production systems.
§ 02 — The three patterns

Single. Multi.
Leaderless.

Every replication scheme in production fits one of three patterns (or some hybrid of them). Each makes different decisions about where writes go — which is the question that drives every other property. Below: the patterns, their canonical diagrams, the systems that use them, and the trade-off each makes explicit.

// THE THREE CANONICAL REPLICATION PATTERNS

Single-Leader
(primary-replica)
// "all writes through one node"
L F F F F writes → L → replicate to all F
"One leader accepts all writes. Followers receive replication."

The classic pattern from M.24. A single node is the authoritative writer; all client writes route there. The leader replicates each change to followers (synchronously, asynchronously, or semi-sync). Reads can come from any replica — though leader-only reads guarantee linearizability while replica reads are eventually consistent.

PostgreSQLMySQL replicationMongoDBRedisetcdCockroachDB
No write conflicts (single source of truth). Simple consistency model. Easy to reason about. Reads scale by adding replicas.
Leader is the bottleneck. Write throughput capped at one machine. Failover requires election (downtime). Cross-region writes pay full RTT.
Multi-Leader
(active-active)
// "writes accepted on multiple nodes"
L₁US-East L₂EU-West L₃AP-South
"Every region writes locally. Leaders gossip changes to each other."

Each region has its own leader that accepts writes. Leaders replicate changes to each other asynchronously. Geographic write locality is the killer feature — a user in Tokyo writes to Tokyo's leader at low latency, then changes propagate to US and EU asynchronously. The cost: conflicts when the same key gets written in two regions before they've synced.

MySQL Group ReplicationPostgres BDRMulti-region MongoDBCouchDBCosmos DB (multi-region)
Low write latency per region. Continues working through inter-region partitions. Higher aggregate throughput than single-leader.
Conflicts are inevitable. Need resolution strategy (LWW, CRDT, app-merge). Complex to reason about. Topology setup is delicate.
Leaderless
(Dynamo-style)
// "no leader · quorum reads and writes"
N N N N N W=2 R=2 client picks W & R
"No leader. Client writes to W nodes, reads from R nodes. Quorum math."

Every node is equal. Clients (or a coordinator) write to W nodes in parallel and read from R nodes. If W + R > N, every read overlaps at least one node that has the latest write — strong consistency through math, not coordination. Background "anti-entropy" keeps replicas in sync over time.

CassandraDynamoDBRiakVoldemortScyllaDB
No leader failover. Per-call consistency (tune W & R). Massive horizontal scale. Highly available even under partition.
Tunable consistency means responsibility on caller. Conflict detection & merge required. Harder to reason about than single-leader.

Notice the pattern: each step "weaker" trades correctness machinery for operational flexibility. Single-leader is the easiest to reason about — one source of truth — but the leader is a bottleneck and a SPOF for writes. Multi-leader breaks the bottleneck and gives geographic locality at the cost of conflict resolution. Leaderless removes the leader entirely, gaining extreme availability and per-call consistency control at the cost of more complex client logic.

None of these is "best." Each fits some workload extremely well and others badly. Postgres with single-leader replication is the right choice for 99% of business applications. Cassandra is the right choice for high-write, write-spreadable workloads at scale. Multi-leader fits global active-active deployments where the latency win justifies the conflict cost. The skill is matching pattern to problem.

§ 03 — Sync vs async vs semi-sync

When is the write
really done?

Within any replication pattern, there's a second knob: how many replicas must acknowledge before the client gets "OK"? This is the synchronicity dial. The three positions trade durability for latency, and you'll see each in production. The default in your favorite database is probably one of them — and you'd be surprised which one.

// THE SYNC DIAL · DURABILITY VS LATENCY

// SYNCHRONOUS
Wait for all replicas
"Don't ack the client until every replica has the write."

Leader writes locally, then waits for every follower to confirm. Strongest durability — if the leader dies right after acking, every follower has the data. Slowest writes — bound by the slowest follower's RTT. A single stuck replica blocks everything.

cost: latency = max(replica RTT) · throughput limited by slowest node
// SEMI-SYNCHRONOUS
Wait for quorum
"Ack when a majority has the write."

Leader waits for quorum acknowledgements (in Raft: majority; in Dynamo-style: W nodes). The pragmatic default for most production systems. Lose the leader and at least one other has it. Faster than full sync because slow tail replicas don't block.

cost: latency = median(replica RTT) · used by Raft, Cassandra QUORUM, MySQL semi-sync
// ASYNCHRONOUS
Don't wait
"Write locally, ack immediately, replicate in background."

Leader writes locally and responds to client immediately. Replication happens in the background. Fastest writes — pure local I/O. Risk: if the leader dies before background replication completes, data is permanently lost. Many production MySQL/Postgres deployments default to this.

cost: latency = local I/O only · risk: window of data loss on leader failure

The choice cascades into your CAP/PACELC trade-off from M.21. Synchronous replication = strong consistency, slow writes, low availability under partition (any unreachable replica blocks). Asynchronous = eventual consistency, fast writes, high availability — but a window of potential data loss if the leader dies during replication lag. Semi-synchronous is the engineering compromise: most of the durability, most of the latency benefit, partition tolerance because slow tails don't block.

Async replication is the silent data-loss risk in half the systems shipping today.

One footgun worth flagging: many systems default to async replication and don't make it loud. MySQL's default replication is async — if your primary dies before its binlog replicates, that data is gone. PostgreSQL's synchronous_commit setting controls this and is often overridden to async for performance. Redis replication is async by default. If durability matters for your data (and it usually does), check the setting explicitly and pick semi-sync at minimum.

§ 04 — Replication pattern comparator · interactive lab

See the same scenarios
play out in each.

Below: pick a replication pattern. Pick a scenario. Watch the topology animate, read what happens, see the verdict. Switch patterns to see how each handles the same scenario differently. Three patterns × three scenarios = nine outcomes you can compare side by side.

REPLICATION.SIM // m.25 lab
// PATTERN · SCENARIO
LOADING
Loading...
Loading...
Loading...
// pattern properties
§ 05 — Conflict resolution

When two writes
both win.

Single-leader avoids conflicts by design — there's only one writer. The moment you have multi-leader or leaderless, conflicts become inevitable: two clients write to the same key on different nodes before replication catches up, and now you have two versions of the truth. The system must decide what to do. Four strategies are common in practice; each makes different trade-offs.

// FOUR STRATEGIES FOR RECONCILING DIVERGENT WRITES

i
Last-Write-Wins (LWW)
"Whichever write has the latest timestamp survives. The other vanishes."

Simplest: each write gets a wall-clock timestamp; the later one always wins on read. Dangerous: it silently discards data. If two clients write concurrently with skewed clocks, one write disappears with no signal. Cassandra defaults to this. Effective when conflicts are rare and approximate truth is acceptable; catastrophic for billing, inventory, or anything ledger-shaped.

ii
Vector Clocks + Sibling Resolution
"Keep both versions when concurrent. Let the app decide on read."

From M.23. Each write carries a vector clock; on read, the system detects concurrent versions (incomparable vectors) and returns both as siblings. The application chooses how to merge: pick one, union, custom logic. The Riak / original-Dynamo model. Honest but pushes work onto the application; you have to actually handle siblings or they accumulate.

iii
CRDTs (Conflict-free Replicated Data Types)
"Design the data so any merge order produces the same result."

A small toolkit of data types (counters, sets, registers, sequences) where the merge operation is commutative, associative, and idempotent — applying writes in any order produces the same final state. Adding "5" to a counter and adding "3" gives 8 regardless of which arrives first. Used in Redis Enterprise, Riak, real-time collaboration (Figma, Google Docs). Beautiful when applicable; limited expressiveness.

iv
Application-Level Merge
"Detect conflict at the system level. Resolve in business logic."

The system flags conflicting versions; the application reads, merges per domain rules, writes back. Examples: a shopping cart unions items from both versions; a profile update uses the most recent change per field. Maximum flexibility, maximum complexity. The reality for most non-trivial multi-leader and leaderless deployments — you'll eventually need this.

The order above is roughly strength of guarantee: LWW is the weakest (loses data), CRDTs are the strongest (mathematically guaranteed convergence), with vector clocks and app-merge in between. The order is also roughly cost of implementation: LWW is one line of code, CRDTs require designing your data model around the constraints. Real systems often layer them: CRDTs for counters and sets, app-merge for complex domain objects, vector clocks underneath both for detection.

And the question worth asking before all of this: can you avoid conflicts entirely by routing writes by key? If a user's profile is always written from their nearest region, you'll never have two regions concurrently writing the same profile. Many "multi-leader" deployments are actually partitioned single-leader under the hood — each shard has one leader, but the leaders are spread across regions. This sidesteps conflict resolution while keeping write locality. It's the cleanest design when your workload allows it.

§ 06 — Eight words for the replication conversation

Vocabulary,
for the topology.

Every term you'll find in the docs of a replicated system and every architecture review involving distributed data.

Replication Factor
/ˌrep.lɪˈkeɪ.ʃən/
The number of copies of each piece of data the system stores. Often written N. Higher = more durable + available, more storage and write amplification. Typical: 3 in same region, 6 across regions.
Sync Replication
/sɪŋk/
Leader waits for all (or quorum) followers to ack before returning to client. Strong durability, higher latency. Used when zero data loss is required.
Async Replication
/ˈeɪ.sɪŋk/
Leader acks immediately, replicates in background. Fast but introduces a data-loss window if leader fails before replication catches up. The default in many systems — often surprisingly.
Failover
/ˈfeɪl.oʊ.vər/
The process of promoting a follower to leader when the current leader fails. Can be automatic (Raft-style election) or manual. Window of unavailability during failover is the headline metric for HA systems.
Anti-Entropy
/ˌæn.tiˈen.trə.pi/
A background process that detects and repairs divergence between replicas. Used heavily in leaderless systems (Dynamo, Cassandra) where there's no leader to enforce order. "Eventually consistent" lives here.
N, W, R
/ɛn ˈdʌb.əl.juː ɑːr/
In Dynamo-style systems: N = total replicas, W = nodes required to ack a write, R = nodes consulted for a read. When W + R > N, you get strong consistency.
CRDT
/siː ɑːr diː tiː/
"Conflict-free Replicated Data Type." A data structure whose merge operation is commutative, associative, and idempotent — any order of writes converges to the same state. Used in real-time collaboration, Redis Enterprise.
Read Repair
/riːd rɪˈpɛr/
When a read in a leaderless system finds inconsistency between replicas, it writes the newest version back to the stale replicas as part of the read response. Opportunistic anti-entropy piggy-backed on read traffic.
§ 07 — Knowledge check

Five questions.
Pick the pattern.

Test the replication intuition. Click an answer; explanation drops in instantly.

QUESTION 1 OF 5
Loading question...
Score: 0 / 5
5 / 5

Replicated.

Perfect. The three patterns and their trade-offs are yours — and so is Phase E. Next phase: events.

§ 08 — The recap

Three ideas to
carry forward.

The replication landscape. These ideas show up in every distributed database conversation and architecture review.

i

Three patterns, three trade-offs

Single-leader: simple, bottlenecked. Multi-leader: geo-local, conflict-prone. Leaderless: highly available, complex. Pick by workload, not by aesthetics.

ii

Sync mode is silent

Most systems default to async replication. That includes a window of data loss on leader failure. Check the setting. Pick semi-sync at minimum for anything that matters.

iii

Conflicts are inevitable

The moment you have multi-leader or leaderless writes, conflicts will happen. LWW, vector clocks, CRDTs, or app-merge — pick consciously, before production teaches you.

◈ PHASE E COMPLETE

Distributed reality.

Five modules. The whole foundation of distributed systems theory — from the impossibility result that makes it hard to the algorithm that made it teachable. Every database, queue, and cache you'll touch from here on out is built on these.

M.21 · CAP Theorem M.22 · Consistency Models M.23 · Lamport Clocks M.24 · Consensus & Raft M.25 · Replication Patterns

When two nodes disagree, you now know exactly why — and exactly what to do about it.

↓ PHASE F BEGINS

M.26 — Message
brokers, deep.

Distributed state under control. Now: distributed communication. Kafka, RabbitMQ, NATS, SQS. The infrastructure that lets services talk reliably across failures, across regions, across time. Event-driven at scale.

Continue to Module 26 →