Skip to content
About
Main content

Durability across machines: replication, quorums and erasure coding

How do copies on several machines raise durability, and what do they cost?

(This article is deliberately short and arithmetic. How replication is organized, how leaders are elected, how repair and failover work, and how membership and fencing are handled are subjects of their own. Here we only keep what changes the meaning of "yes" and the odds of losing data.)

Replication as durability: positions on the ack ladder

For durability, replication matters in one way: when does the primary say "yes"? Three common positions:

ModeThe primary says "yes" when...SurvivesCostDoes not survive
Asynchronousits own log is durable, without waiting for any replicaa restart of the primary (rung 4 only)noneloss of the primary machine: the last moments of writes can be lost
Semi-synchronousat least one replica has received (written to its own log or memory) the recordloss of the primary machine, as long as the replica survives+1 network round trip (RTT), about 0.2–1 ms in the same availability zonea replica that acknowledged receipt but had not yet made it durable
Synchronousat least one replica has made the record durable on its own medialoss of the primary machine and of the replica's process; rung 5+1 RTT plus the replica's flushsimultaneous loss of both

(Rule: and one more flush on another machine.)

In Postgres the position is a pair of settings. synchronous_standby_names names the replicas the primary waits for, and synchronous_commit says how far: remote_write (the replica has received the record and handed it to its operating system: semi-synchronous), on (the replica has flushed it: synchronous) or remote_apply (it is also visible to queries on the replica). With no replica named, every setting is asynchronous.

The acknowledged-but-not-committed window

Every mode below synchronous has a window in which the client has been told "committed" and the record is not yet durable on a second machine. With asynchronous replication the window is the whole replication lag: whatever has not reached a replica when the primary dies is lost, even though the client was told it was committed. This is Nadia's 300 ms of missing transfers. With semi-synchronous replication the window shrinks: a replica can acknowledge receipt of a record, and the primary can say "yes" to the client. If the primary and that replica then fail before the record is applied anywhere durable, the record is lost.


Quorum writes: the durability arithmetic of W, R and N

In a system, data is stored on N replicas. A write succeeds when W of them confirm it. A read asks R of them.

The usual rule W + R > N is taught as a consistency statement: any read set overlaps any write set in at least one replica, so a read sees the latest write. Here we use it as a durability statement, and the quantity that matters for durability is W, not the overlap rule:

  • W is the number of copies that exist when you say "yes". If W = 1, one machine failing right after the can destroy the only copy. If W = 2, you survive any single failure.
  • W + R > N says nothing about how many machines can fail without data loss. That is decided by W (and by the failure domains in which those W copies live).

Durability arithmetic under correlated failure

Before the arithmetic, one assumption has to be said out loud: replication, quorums and erasure coding all divide by a failure probability that is assumed to be independent. What really kills clusters are correlated failures: the same rack, the same firmware version, the same bad manufacturing batch, the same bad deploy, the same operator.

MTTDL (Mean Time To Data Loss) is the usual figure of merit. A simplified estimate for 3 replicas assumes: each disk fails independently with yearly probability p, and a failed disk is rebuilt within a short repair window.

Now add correlation. The three disks came from the same batch, in the same rack, with the same firmware. Suppose the batch has a defect that makes the yearly failure probability of all its disks 5% together (one common cause). Then the chance of losing all three in a year is on the order of 0.05, not 10⁻⁶: about 50,000× worse. In practice, computed under independence overstates real durability by orders of magnitude. So:

  • Replication factor buys much less than p^N once batch, rack and software correlation are included.
  • The cheap gains come from spreading the copies across failure domains (different racks, different zones, different software versions or vendors), more than from adding a fourth copy in the same domain.
  • (When the storage lies) is correlated within a drive and batch, so it is a as well.