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.
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.
# 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
Runs on this device, in your browser. The first run downloads Python (about 13.5 MB), which is kept for the next runs.
Your run, in this browser
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.
| Criterion | 3 copies | RS (10, 4) |
|---|---|---|
| Stored per byte | 3.0 | 1.4 |
| Losses survived | Any 2 | Any 4 |
| Rebuild one lost piece | Read 1 copy | Read 10 pieces |
| Read a missing piece | Read another copy | Read 10 pieces, decode |
| When to choose | Hot, small or changing data | Large, cold data |
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.
- 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.
- 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:
The drawing shows the whole scene; its 6 steps are listed below.
Every step as text
- 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.
- 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.
- 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.
- 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.
- 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.
- 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
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.
Passes can’t be bought right now, so this part can’t be opened at the moment. The free part above stands on its own. If you have a pass, enter your licence key.
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).
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
- HDFS Erasure Coding (The Apache Software Foundation)
- Erasure code (Ceph documentation) (Ceph Foundation)
- Polynomial Codes over Certain Finite Fields (Reed and Solomon) (Journal of the Society for Industrial and Applied Mathematics)
- Erasure Coding in Windows Azure Storage (USENIX ATC 2012) (USENIX)
- f4: Facebook's Warm BLOB Storage System (OSDI 2014) (USENIX)
- Finding a needle in Haystack: Facebook's photo storage (OSDI 2010) (USENIX)
- A Case for Redundant Arrays of Inexpensive Disks (RAID), UCB/CSD-87-391 (University of California, Berkeley (Patterson, Gibson and Katz))
- Backblaze Drive Stats (hard drive data and annualised failure rates) (Backblaze)
Related tools
Report a problem with this lesson
Kept only in this browser. Your Learn progress