System designLoading progress…

Replication paths

Compare consistency contracts and distribute data while tracing stale reads, partitions and hot keys.

Replication paths

Replicas protect data and spread reads, but when does a write count as done? With asynchronous replication the leader acknowledges after storing the write itself: fast (5 ms here) but only one copy exists, followers lag, and a leader crash can lose an acknowledged write. With synchronous replication to one follower the acknowledgement waits for a second copy (25 ms in the example), so a failover keeps the write. Say precisely which condition your "durable" refers to.

copies required before acknowledging1
leader: v1follower 1: behindfollower 2: behind
Step 1 of 4
1. client sends write v1 to the leader

What "persisted" or "replicated" means depends on when the write is acknowledged. Asynchronous replication is fast but followers lag and an acknowledged write can be lost; synchronous waiting makes it durable on more nodes at the price of latency.

Choose how many copies to wait for, and crash the leader.

Predict first. Can an asynchronous follower lag after a successful leader write?

Chapter context

Replication copies data for resilience or read capacity; partitioning assigns different data to different owners. Both introduce coordination and failure behavior that an application must explicitly account for.

Chapter reference: math, worked example & code

This section belongs to the whole chapter, so it is the same on every lesson in it and may cover a different lesson's topic. The code for the experiment you just ran is inside the experiment itself.

Math and notation

For fixed sets over N replicas, ∣R∩W∣≥∣R∣+∣W∣−N|R\cap W|\ge |R|+|W|-N. Thus R=W=3 with N=5 forces at least one shared member. This is a set fact, not a complete consistency proof. Shard and replication counts describe different dimensions of the layout.

Worked example

Five replicas use read sets and write sets of size three. The lower bound on overlap is 3+3−5=1. Enumerating all three-member sets confirms every pair overlaps. A read still needs the right version-selection and concurrency rules; intersection alone does not tell which stored value is newest or committed.

Reference code

The following example uses the Python standard library and does not call a remote service.

from itertools import combinations
replicas=set(range(5))
sets=[set(x) for x in combinations(replicas,3)]
assert min(len(r&w) for r in sets for w in sets) == 1
assert 3+3-5 == 1
assert all(r&w for r in sets for w in sets)

Python examples are provided for study and local execution; this page does not execute Python.

Common mistakes

Quorum arithmetic does not establish a full consistency contract. Sharding is not replication. CAP availability is a precise failure-model property, not the same as an ordinary monthly uptime percentage.