SysDesignPrep.com
Interactive concepts

Replication vs erasure coding: an interactive durability simulator

Storage systems protect data against disk failures in two ways. Replication keeps whole copies, usually three, on different disks. Erasure coding splits data into k fragments, computes m parity fragments, and can rebuild everything from any k of the k + m. Reed-Solomon RS(6, 3) survives any three lost disks, one more than three copies, using half the space. What it costs is repair: rebuilding one lost fragment means reading k others.

The playground compares five schemes for 10 petabytes of data. Change how often disks fail and how long a repair takes, and compare raw storage, durability and repair traffic.

SchemeDisk failures a yearTime to repair

RS(6, 3): each object split into 6 data fragments plus 3 parity fragments, any 6 of which rebuild it, on 9 different disks. It survives 3 lost disks at once and needs 1.5× the raw capacity: 15 PB to store 10 PB. With disks failing at 2% a year and 24 hours to rebuild one, each stripe has 11.8 nines of durability, a 1 in 600 billion chance a year of losing data. Across the 156,250,000 stripes of 10 PB, that is a 1 in 3,859 chance of losing anything in a year. Against 3 copies, it saves 15 PB of disks and is more durable. The catch is repair: rebuilding a failed 16 TB disk means reading 6 fragments for each lost one, 96 TB across the network instead of 16 TB, and reading data while a fragment is missing is slower too.

Durability against storage overhead
04812161×1.5×2×3×raw storage per byte storednines a year2 copies3 copiesRS(4, 2)RS(6, 3)RS(10, 4)
One stripe of RS(6, 3)
d1d2d3d4d5d6p1p2p3
9 disks; any 6 fragments rebuild the data, so 3 can fail.
Raw storage for 10 PB
15 PB
Durability
11.8 nines
Read to rebuild a 16 TB disk
96 TB
Disks that can fail at once
3

Durability assumes independent disk failures. Real systems are limited by correlated ones, a rack, a power feed or a bad batch of disks, which is why fragments are spread across racks and zones.

How erasure coding works

  1. Split each object, or a large block of objects, into k equal data fragments.
  2. Encode m parity fragments from them. With one parity fragment it is simply the XOR of the data; Reed-Solomon codes produce any number using arithmetic over a finite field.
  3. Spread the k + m fragments across different disks, servers and ideally racks or zones.
  4. Read normally from the k data fragments; if some are missing, read any k of the survivors and decode.
  5. Repair a lost fragment by reading k others and recomputing it.

Durability per byte of disk

Data is lost only if more than m of a stripe’s disks fail before repairs finish. Three copies tolerate two failures at 3× storage; RS(6, 3) tolerates three at 1.5×; RS(10, 4) tolerates four at 1.4×. With disks failing at 2% a year and a day to repair one, the playground puts three copies at about 9.7 nines of durability per stripe a year and RS(6, 3) at 11.8, for 15 PB of raw disk to store 10 PB instead of 30. Two copies, by contrast, manage under 6 nines: at that scale hundreds of stripes would be lost every year.

Repair time matters as much as the scheme, because a second failure only hurts while the first is being repaired. Stretch repairs from a day to a week and RS(6, 3) drops from 11.8 nines to about 9.2. Systems repair in parallel across many disks so a lost disk is rebuilt in minutes, not the hours it would take to copy it to one replacement.

The cost: repair traffic and degraded reads

Replacing a lost replica means copying one surviving copy: a 16 TB disk needs 16 TB read. Replacing a lost RS(6, 3) fragment means reading six fragments, 96 TB across the network for the same disk; RS(10, 4) reads 160 TB. Reads of data whose fragment is missing are slower too, since they must fetch and decode k others. Newer codes, such as the locally repairable codes used in Azure Storage, add local parity so most repairs read fewer fragments.

Where each is used

  • Replication for hot, small or frequently updated data, where fast reads and cheap repairs matter more than space: databases, Kafka, the replicas behind a key-value store.
  • Erasure coding for large, mostly cold, write-once data, where space dominates: object stores such as S3 and Azure Blob, HDFS with erasure-coding policies, backups and archives.
  • Both: many systems write new data replicated and erasure-code it in the background once it cools.

The idea in code

# the simplest erasure code: one parity fragment, XOR of the data fragments (RAID 5's idea)
def encode(data: bytes, k: int) -> list[bytes]:
    size = -(-len(data) // k)
    frags = [data[i * size:(i + 1) * size].ljust(size, b"\0") for i in range(k)]
    parity = bytes(size)
    for f in frags:
        parity = bytes(a ^ b for a, b in zip(parity, f))
    return frags + [parity]                     # k + 1 fragments on k + 1 disks

def rebuild(frags: list[bytes | None]) -> list[bytes]:
    missing = frags.index(None)                 # survives any one lost fragment
    out = bytes(len(next(f for f in frags if f)))
    for f in frags:
        if f is not None:
            out = bytes(a ^ b for a, b in zip(out, f))
    frags[missing] = out
    return frags

# Reed-Solomon generalises this to m parity fragments surviving any m losses,
# using arithmetic over a finite field instead of plain XOR.

In a system design interview

When you store petabytes, say how it survives and what it costs: “Uploaded videos are written with three replicas so they can be served at once; after a day, a background job erasure-codes them with RS(6, 3) across three zones, which halves the disk bill and still survives losing a zone. Fragments are rebuilt in parallel from many disks, so a failed disk is repaired within an hour.” Expect the follow-ups: what happens to read latency when a fragment is missing, correlated failures, and how small objects are packed into large stripes.

Read the guide to object storage or distributed file systems, or watch a strong candidate design YouTube, where storage is the largest bill.

Questions people ask

What is erasure coding?

A way to protect stored data by splitting it into k data fragments and computing m extra parity fragments, so that the original can be rebuilt from any k of the k + m. The fragments go on different disks or servers, and the data survives the loss of any m of them, with far less extra storage than keeping full copies.

What is the difference between replication and erasure coding?

Replication stores whole copies, typically three, so it needs 3× the space and survives two failures, but reads and repairs are simple and cheap. Erasure coding such as RS(6, 3) needs 1.5× the space and survives three failures, but rebuilding a lost fragment means reading six others, and reads with a missing fragment must decode.

What does RS(6, 3) mean?

A Reed-Solomon code with 6 data fragments and 3 parity fragments, 9 in total, spread across 9 disks. Any 6 of them rebuild the data, so up to 3 can be lost, and the storage overhead is 9/6, or 1.5×. RS(10, 4) is 14 fragments, any 10 sufficient, at 1.4×.

Why is erasure coding cheaper than replication?

Because parity fragments protect a whole group of data fragments at once. Protecting against three failures with copies needs four full copies, 4× the space; with RS(6, 3) it needs 1.5×. At petabyte scale that difference is most of the hardware bill, which is why object stores and archives use erasure coding.

What are the downsides of erasure coding?

Repair and degraded reads are expensive: rebuilding one lost fragment requires reading k surviving fragments over the network, and reading data whose fragment is unavailable means fetching and decoding k others. Small or frequently updated data fits poorly, so erasure coding is mostly used for large, cold, write-once data.

How is storage durability calculated?

Data is lost if more than m fragments of a stripe are lost before repairs complete, so durability depends on the disk failure rate, the time to repair a failed disk, and m. With independent failures, the annual loss probability falls steeply with faster repairs and more parity. Real estimates must also account for correlated failures across racks, power and batches of disks.

Why does repair time matter so much for durability?

Data is only at risk while redundancy is reduced, between a failure and the end of its repair. Shorter repairs shrink the window in which further failures can pile up. Large systems rebuild a failed disk in parallel from many other disks, taking minutes instead of the hours needed to copy it to a single replacement.