Your country

Tools that support it use your country for local currency, number formats, units and paper size. Your choice is saved only in this browser.

Type a name or a two-letter code. Use the up and down arrow keys to move through the countries, Enter to choose one and Escape to close.

System Design (High-Level Design)  Module 15 – Files, objects and media

Durability: replication vs erasure coding

Compare whole copies with Reed-Solomon erasure coding on storage overhead, failures survived and repair cost, and place the pieces across zones and racks.

  • Advanced
  • 20 minutes
  • Examples run with Python 3.14.8, Pyodide 314.0.7, Node.js 24.21.0 and quickjs 0.32.0
  • By MySmartCoPilot
Free intro, Pro: 4 of 20 minutes free
Free: Copies, pieces and what each survives. With a pass: the other 9 sections and 3 interview answers, about 16 minutes.

What you will learn

  • Compare replication and erasure coding on overhead, failures survived and repair cost
  • Rebuild a lost block from XOR parity, and explain why one parity block cannot undo two losses
  • Read an erasure-coding policy such as RS (10, 4) and compute what it costs
  • Plan where the pieces of a stripe go so that a zone outage loses no data
  • Choose which data to keep as copies and which to erasure-code, from its temperature and its repair cost

Before you start

What you’ll learn · Before you start

What you will learn

  • Compare replication and erasure coding on overhead, failures survived and repair cost
  • Rebuild a lost block from XOR parity, and explain why one parity block cannot undo two losses
  • Read an erasure-coding policy such as RS (10, 4) and compute what it costs
  • Plan where the pieces of a stripe go so that a zone outage loses no data
  • Choose which data to keep as copies and which to erasure-code, from its temperature and its repair cost

Before you start

On this page

A storage system keeps data durable by storing more than one byte for every byte it is given. Replication stores whole copies: three copies cost 3 bytes per byte and survive the loss of any two. erasure coding: Storing data as data blocks plus parity blocks computed from them, so that lost blocks can be rebuilt from the rest. With 6 data and 3 parity blocks it keeps 1.5 raw bytes per byte, half of what three full replicas need, at extra CPU and network cost. More in “Estimating storage, bandwidth and cache memory” cuts the data into k pieces and computes m parity pieces from them, and any k of the k + m pieces rebuild the data: Reed-Solomon (10, 4) costs 1.4 bytes per byte and survives any four lost pieces. Erasure coding therefore protects as well or better on half the disks or fewer, and pays when a piece is lost, because rebuilding one piece reads k others. That is why most large stores keep hot data replicated and erasure-code data once it has cooled.

Copies, pieces and what each survives

Three numbers describe a scheme: the bytes it stores per byte of data, how many lost pieces it survives, and how many pieces a repair reads to rebuild one. The example computes them for the schemes this lesson compares.

Overhead, losses survived and repair reads Python · overhead/ec_overhead.py
# Copies against fragments: what each scheme stores per byte of data, how many lost pieces it survives, and how many
# pieces a repair reads to rebuild one. Replication keeps n whole copies; a (k, m) erasure code cuts the data into k
# fragments, adds m parity fragments, and rebuilds the data from any k of the k + m.
SCHEMES = [
    # name, data pieces k, extra pieces m, pieces read to rebuild one lost piece
    ("2 copies", 1, 1, 1),
    ("3 copies", 1, 2, 1),
    ("XOR parity (2, 1)", 2, 1, 2),
    ("Reed-Solomon (6, 3)", 6, 3, 6),
    ("Reed-Solomon (10, 4)", 10, 4, 10),
]

print(f"{'scheme':<22}{'pieces':>7}{'stored per byte':>17}{'survives':>10}{'repair reads':>14}")
for name, k, m, reads in SCHEMES:
    n = k + m
    print(f"{name:<22}{n:>7}{n / k:>17.2f}{m:>7} lost{reads:>14}")

print("\nFor 1 PB of data:")
for name, k, m, _ in SCHEMES:
    print(f"  {name:<22}{(k + m) / k:>5.2f} PB of disk")

Output

scheme                 pieces  stored per byte  survives  repair reads
2 copies                    2             2.00      1 lost             1
3 copies                    3             3.00      2 lost             1
XOR parity (2, 1)           3             1.50      1 lost             2
Reed-Solomon (6, 3)         9             1.50      3 lost             6
Reed-Solomon (10, 4)       14             1.40      4 lost            10

For 1 PB of data:
  2 copies               2.00 PB of disk
  3 copies               3.00 PB of disk
  XOR parity (2, 1)      1.50 PB of disk
  Reed-Solomon (6, 3)    1.50 PB of disk
  Reed-Solomon (10, 4)   1.40 PB of disk

Recorded with Python 3.14.8 on macOS 26 arm64. To run it yourself: mise exec python@3.14.8 -- python3 ec_overhead.py

The HDFS documentation makes the same comparison for its default policy: six blocks stored three times use 18 blocks of disk, while 6 data and 3 parity blocks use 9 (HDFS erasure coding). So Reed-Solomon (6, 3) survives three lost pieces where three copies survive two, on half the disk. The last column is the catch. Rebuilding a lost copy reads one surviving copy; rebuilding a lost Reed-Solomon piece reads six or ten.

Replication or erasure coding
Criterion 3 copiesRS (10, 4)
Stored per byte 3.01.4
Losses survived Any 2Any 4
Rebuild one lost piece Read 1 copyRead 10 pieces
Read a missing piece Read another copyRead 10 pieces, decode
When to choose Hot, small or changing dataLarge, cold data
Three whole copies, one per zone, against a Reed-Solomon (6, 3) stripe with three of its nine pieces in each zone.Three copies: 3 bytes per byte,any 2 of 3 lostReed-Solomon (6, 3): 1.5 bytesper byte, any 3 of 9 lostZone AZone BZone CcopycopycopyZone AZone BZone Cdata 1data 4parity 1data 2data 5parity 2data 3data 6parity 3

Copies or fragments, across three zones

Text description of the diagram

The diagram has two panels, one under the other, each with three zones side by side.

  1. Three copies: zone A, zone B and zone C each hold a whole copy of the data. That stores 3 bytes for every byte of data, and any 2 of the 3 copies may be lost.
  2. Reed-Solomon (6, 3): the data is cut into 6 data pieces and 3 parity pieces are computed from them. Zone A holds data pieces 1 to 3, zone B data pieces 4 to 6, and zone C parity pieces 1 to 3. That stores 1.5 bytes for every byte of data, and any 3 of the 9 pieces may be lost, so the loss of a whole zone still leaves 6 pieces, enough to rebuild the data.

Where the pieces sit matters as much as how many there are. A failure domain: A set of disks or machines that one fault can take down together, such as a host, a rack, a power feed or a zone. Copies or pieces of the same data are spread across failure domains so that one fault cannot take them all. is anything that can take many disks down at once: a host, a rack, a power feed, a zone. Three copies in three zones survive a zone outage, and so does a Reed-Solomon (6, 3) stripe with three pieces in each zone, as drawn above. Step through both layouts as the zones fail:

Interactive · step by step Three copies and an RS (6, 3) stripe through zone outages Step through the loss of one zone, then of a second. The left column holds the three copies, the right column the nine pieces of the stripe.
Three copies and an RS (6, 3) stripe through zone outages, step 6 of 6. Showing Zone A: a copy (down), Zone B: a copy (down), Zone C: a copy (a copy), Zone A: data 1 to 3 (down: 3 pieces lost), Zone B: data 4 to 6 (down: 6 pieces lost), Zone C: parity 1 to 3 (parity 1 to 3). In focus: Zone C: a copy, Zone C: parity 1 to 3.Zone A: a copydownZone B: a copydownZone C: a copya copyZone A: data 1 to 3down: 3 pieces lostZone B: data 4 to 6down: 6 pieces lostZone C: parity 1 to 3parity 1 to 3

The drawing shows the whole scene; its 6 steps are listed below.

Every step as text
  1. Both layouts, healthy. Three copies store 3 bytes for every byte and survive any 2 lost copies. The RS (6, 3) stripe stores 1.5 bytes per byte and survives any 3 lost pieces of its 9.
  2. Zone C fails. Zone C goes down. Two copies are left on the left. On the right the three parity pieces are gone, but all six data pieces are there, so reads go on without decoding.
  3. Zone A fails instead. Suppose zone A had failed instead. Two copies are left again. The stripe loses data 1 to 3, but 6 of its 9 pieces remain, data 4 to 6 and parity 1 to 3, enough to rebuild the data by decoding.
  4. A degraded read. Until zone A is back or repaired, a read of data 1 has to fetch six other pieces and decode them. That is the price of the parity, paid only while a piece is missing.
  5. A second zone fails. Now zone B fails as well. One copy is left, so the copies can still be read. The stripe keeps only parity 1 to 3, 3 pieces where it needs 6, so it cannot be read until a zone returns.
  6. The trade. Both survive one lost zone; three copies also survive two, and pay twice the disk for it. How many failure domains a scheme must survive decides which one fits.

The rest of the design follows from a few more ideas, each in one sentence. XOR parity is the simplest erasure code: one parity piece rebuilds any single lost piece. Reed-Solomon codes extend it to m parity pieces, so any m pieces may be lost. Local reconstruction codes add parity for small groups, so most repairs read a few pieces instead of k. A degraded read: A read of erasure-coded data whose wanted piece is missing: the reader fetches enough other pieces of the stripe and decodes the missing one, which costs more reads and CPU than a normal read. fetches other pieces and decodes when the piece it wanted is missing. Repair time is the window in which further failures can turn a damaged stripe into lost data.

Checkpoint

Check: Copies, pieces and what they survive

  1. Question 1 of 2 A policy RS (8, 3) cuts data into 8 data pieces and adds 3 parity pieces. How many bytes does it store per byte of data?

    Type a number.

    A hint

    Count all the pieces, then divide by the data pieces.

    Show the answer: Question 1 of 2

    Answer: 1.375 bytes (anything from 1.365 to 1.385 counts)

    It stores 8 + 3 = 11 pieces for 8 pieces of data, so 11 ÷ 8 = 1.375 bytes per byte, and any 3 of the 11 pieces may be lost. Three copies would store 3 bytes per byte and survive 2 losses.

  2. Question 2 of 2 Three copies sit one per zone, and an RS (6, 3) stripe has three pieces in each of the same three zones. Two zones fail. Which can still be read?

    Choose one answer.

    Show the answer: Question 2 of 2

    Answer: Only the three copies, because one copy is left while the stripe keeps 3 of the 6 pieces it needs

    Each copy is complete, so one is enough. The stripe needs any 6 of its 9 pieces, and two lost zones leave only 3. Both schemes survive one zone; only the copies survive two, at twice the disk.

How parity rebuilds a lost block, in code Pro: opens with a Pro, Premium or Ultimate pass

In this part:

  • From one parity piece to any m: Reed-Solomon
  • Durability in numbers: repair time is the lever
  • Placement: a zone outage, simulated
  • What repairs and degraded reads cost, with numbers
  • Hot data replicated, cold data erasure coded
  • Practise: choose an erasure-coding policy
    • Read an erasure-coding policy and place it across zones
  • Interview questions
    • What does an erasure-coding policy such as RS (10, 4) mean, and what does it cost and survive?
    • You must store 40 PB of cold video archives in one region with three zones. The data must survive the loss of a whole zone, and disk is the biggest cost. Which coding scheme and placement do you choose, and what does it cost?
    • A rack of 40 disks of 20 TB each fails in a cluster that stores everything as RS (10, 4). Estimate the repair traffic and how long the repair takes, and say what you would do to keep data safe while it runs.
    • Large object stores often write new data as copies and convert it to erasure coding later. Defend that policy with numbers, and say which data you would never erasure-code.
  • Key takeaways

3 diagrams · 4 runnable examples (Python) · 1 exercise with sample tests · 3 interview answers · about 48 minutes

Opening this part with your pass…

This part opens with any MySmartCoPilot pass.

  • Pro pass · 1 week₹79$2.99
  • 30 days₹179$5.99
  • 1 year₹1,699$45

One payment; a pass never renews. The price shown is the total you pay: no fees or charges are added at checkout.

It also opens every other in-depth part in Learn and every Pro tool. Sales are final, except where the law gives you a right to withdraw, for example in the EU and the UK (refund policy).

Read a complete sample first: Design a unique ID generator

Terms in this lesson

annualised failure rate (AFR)
The share of drives expected to fail in a year, worked out from the failures seen over the drive days observed; 1.41 % means about 14 failures a year in every 1,000 drives.
degraded read
A read of erasure-coded data whose wanted piece is missing: the reader fetches enough other pieces of the stripe and decodes the missing one, which costs more reads and CPU than a normal read.
durability
The chance that stored data is not lost over a period, usually a year, often written as a number of nines: 99.999999999 % is eleven nines.
failure domain
A set of disks or machines that one fault can take down together, such as a host, a rack, a power feed or a zone. Copies or pieces of the same data are spread across failure domains so that one fault cannot take them all.

References

Related tools

Report a problem with this lesson

Quick answers and tool search

Type to search tools or to get a quick answer, for example 18% of 2500. Use the up and down arrow keys to move through the results, Enter to choose, and Escape to close.