SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
  • Block Storage
  • Distributed File Systems
  • Object Storage
  • Erasure Coding
  • Storage Tiers (Hot, Warm, Cold)
  • RAID
  • Compression and Deduplication
  • File Storage (NFS)
Part 5: Architecture
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Data and Storage/Storage Systems

Erasure Coding

Survive lost disks using clever maths, with less extra space than full copies.

⏱ 13 min readAdvancedInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

Erasure coding protects data from lost disks without making full copies. It cuts data into k data pieces, adds m parity pieces made by maths, and stores all k + m pieces on different disks.

  • Any k of the k + m pieces can rebuild the data. So you can lose up to m pieces and still recover.
  • The extra space is only (k + m) / k. For 6+3 that is 1.5x, compared with 3x for three full copies.
  • The price is more CPU and more network traffic when you read a damaged object or repair a lost piece.

02Concept: What is it?

The simple way to survive a broken disk is replication: keep 3 copies. It is easy and fast, but you pay for 3x the space. For petabytes of data, that is a huge bill.

An erasure code gets the same safety with less space. It is the same idea as a crossword puzzle with some letters wiped out: if the rest of the puzzle carries enough clues, you can fill in the gaps. In storage, the "clues" are parity pieces, computed from the data. The word "erasure" means we know which piece is lost (the disk is dead), which is easier than finding hidden errors.

Replication vs erasure coding for the same safety
3 copies (replication)
📄Copy 1
📄Copy 2
📄Copy 3
Space used3.0x, survives any 2 lost
6 data + 3 parity (erasure coding)
D
D
D
D
D
D
P
P
P
Space used1.5x, survives any 3 lost
Both survive losing 2 disks. Erasure coding stores much less.
🧠The one rule
With k data and m parity pieces, any k pieces are enough. Lose up to m, and you are fine. Lose m + 1, and the data is gone.

03Real-Life Example

🍵The Missing Number Trick
You tell a friend three numbers: 5, 9 and 4. To protect against a mistake, you also say their total: 18. Later your friend forgets the 9. They can work it out: 18 minus 5 minus 4 equals 9. You stored 4 numbers instead of 3, and now you can survive one loss. That is a tiny erasure code. Real codes use cleverer arithmetic, so that with several extra numbers you can survive several losses.
Total trick
Erasure coding
The numbers 5, 9, 4
k data pieces
The total, 18
A parity piece
Forgetting one number
A failed disk (an erasure)
Working it out from the rest
Decoding from the survivors
Needing 3 of the 4 values
Any k of the k + m pieces
Extra totals using different weights
More parity pieces (Reed-Solomon)
Doing arithmetic takes some effort
Encoding and decoding use CPU
Encode, store, lose, decode
📦Object
→↓split + encode
🧮k data + m parityon different disks
→↓m disks die
🧩k survivorsstill enough
→↓decode
✅Object back

04Why Do We Need It?

💸Much cheaper at scale
1.2x to 1.5x space instead of 3x. For an exabyte that saves vast amounts of hardware.
🛡️High durability
With 6+3 you can lose 3 disks. Three-way replication loses data after 3 losses too, at double the space.
🌍Spread over zones
Pieces can sit in different racks, zones or regions, so whole-site failures are survived.
🧮Tune the trade
Choose k and m to balance cost, safety and repair work.
🧊Great for cold data
Data that is rarely read does not need the cheap reads of full copies.
📈Eleven-nines goals
Large object stores use codes like this to reach very high durability affordably.
Replication buys safety with space. Erasure coding buys the same safety with maths, and pays in CPU and network.

05Where Do We Use It?

🪣Object stores
Large cloud object stores keep data durable with codes across disks and zones (general idea).
🐘HDFS
Hadoop 3 added erasure coding, such as RS(6,3), to cut storage compared with 3 copies.
🧲Ceph
Erasure coded pools with settings like k=4, m=2.
💽RAID
RAID 5 (one parity) and RAID 6 (two parities) are small erasure codes inside one machine or array.
📡Networks and media
QR codes, CDs and satellite links use Reed-Solomon codes to fix damage.
🗄️Cold data tiers
Backups, logs and video archives where reads are rare.

06Types / Parts / How It Works

Common codes

CodeIdeaGood and bad
XOR parity (RAID 5)One parity piece, the XOR of the data pieces. Survives one loss.Very simple and cheap. Only one failure allowed.
Reed-Solomon (k, m)Treats the data as numbers in a special number system (a Galois field). Makes m parity pieces. Any k of the k + m can decode. Survives m losses.The classic choice. Repair needs k pieces read.
Local reconstruction codes (LRC)Adds small local parity groups, so a single failure needs only a few pieces to repair, plus global parity for bigger failures.Cheaper repair. Slightly more space than Reed-Solomon. Used in Azure and Facebook designs.
Regenerating codesResearch designs that reduce the data moved during repair.Less repair traffic. More complex.
Fountain / rateless codesMake an endless stream of coded pieces. Any enough of them rebuild the data.Used in broadcasting and some transfers.

Popular layouts

Layout (k + m)SpaceSurvivesNotes
3 copies3.0x2 lostNot erasure coding, shown for comparison. Fast reads, simple repair.
4 + 21.5x2 lostCommon in small clusters (Ceph example).
6 + 31.5x3 lostHDFS built-in policy RS-6-3.
10 + 41.4x4 lostSeen in large warehouses (Facebook HDFS RAID used 10+4).
12 + 41.33x4 lostNeeds at least 16 failure domains.
Replication (3 copies)
Simple and fast
  • 3x storage
  • Read from any one copy
  • Repair copies one piece
  • Low CPU
Erasure coding
Compact and smart
  • About 1.2x to 1.5x storage
  • A degraded read must fetch k pieces
  • Repair reads k pieces to make one
  • Needs CPU for the maths
Why repair costs more
Replication repair
📄1 survivor
→↓1 read
📄New copy
6+3 repair
🧩6 survivors
→↓6 reads
🧮Decode
→↓
🧩New piece
With replication a lost copy needs one read. With 6+3, one lost piece needs six reads, so repair traffic is up to 6x.
Visualizerk data + m parity: fail pieces, compare with 3 copies, try XORTab 1: change k and m, click pieces to fail them, and see when data is lost and what it costs. Tab 2: lose one piece in the XOR demo and watch it get rebuilt.
One object, 9 pieces on 9 disks. Cyan = data piece, purple = parity piece. Click a piece to fail its disk.
Survivors vs needed:
9 / 6 needed
Layout
6+3
survives any 3 lost
Space used
1.50x
of the original size
3 copies use
3.00x
you save 50%
Data
safe
0 failed
Loss chance 6+3
1.9 x 10^-5
more than 3 of 9 fail
Loss chance 3 copies
8.0 x 10^-6
all 3 fail
The object is cut into 6 data pieces and 3 parity pieces, stored on 9 different disks. Click pieces to fail them.

The rule for this kind of code (called MDS, such as Reed-Solomon): any k of the k+m pieces can rebuild the data. The loss chance assumes disks fail independently with the chance you picked. Real systems repair fast and spread pieces over racks and zones, so real numbers differ. Notice how 3 copies (1 data + 2 extra) costs 3x, while 6+3 survives more failures for only 1.5x.

07How to Use It / Steps / Implementation

Choosing and running an erasure code

  1. 1
    Decide the failures you must survive
    How many disks, racks or zones can fail at once? That number is m, and the pieces must sit in at least that many separate failure domains.
  2. 2
    Pick k for the cost you want
    Larger k with the same m lowers the overhead (for 6+3: 1.5x, 12+3: 1.25x). But reads and repairs touch more pieces.
  3. 3
    Spread the pieces
    Put each of the k + m pieces on a different disk, node and, if you can, rack or zone. Pieces on the same machine fail together.
  4. 4
    Stripe the data in cells
    Data is cut into small cells (for example 1 MB in HDFS) and written round-robin over the k data pieces. Parity is computed per stripe.
  5. 5
    Read normally from the data pieces
    When all k data pieces are up, a read just reads them. No decoding is needed.
  6. 6
    Degraded read and repair
    If a piece is missing, read any k others and decode. A background repair job rebuilds missing pieces onto new disks.
  7. 7
    Keep hot data replicated
    A common design is 3 copies for new, hot or small objects, and erasure coding when the data is older, larger and cooler.
💡Small objects do not fit well
Cutting a 4 KB object into 6 pieces gives tiny pieces and many I/Os. Many systems keep small objects replicated, or pack them into large blocks first, and erasure-code the large blocks.
⚠️Fast repair matters for durability
Data is lost when more than m pieces fail before repair finishes. A slow repair keeps you in the danger zone for longer. Plan network and disk capacity for repair, not only for normal reads.

08Key Terms to Know

TermMeaning in easy words
Erasure codeA way to add parity pieces so that lost pieces (erasures) can be rebuilt
kThe number of data pieces. Any k pieces are enough to rebuild the data.
mThe number of parity pieces. This is how many losses can be survived.
ParityExtra information computed from the data pieces, used to rebuild lost ones
Reed-SolomonThe classic erasure code. Uses arithmetic in a Galois field, a number system with a finite size.
XORA bit operation that is 1 when two bits differ. The simplest parity.
Storage overheadTotal stored size divided by original size, (k + m) / k
StripeOne group of k data cells plus its m parity cells
Degraded readA read made while some pieces are missing, so decoding is needed
Repair / reconstructionRebuilding lost pieces onto new disks
Failure domainA set of things that fail together, like a disk, a server, a rack or a zone
MDS codeMaximum distance separable: the best possible code, where any k of k + m pieces work
LRCLocal reconstruction code: adds local parity so a single repair reads fewer pieces

09Pros, Cons and Trade-offs

✅ Pros
  • Far less space than copies (1.2x to 1.5x vs 3x)
  • Same or better durability
  • Pieces can span racks and zones
  • Flexible: tune k and m
  • Great for large, cold data
⚠️ Cons
  • CPU for encode and decode
  • Repair reads many pieces, so network traffic is high
  • Degraded reads are slower
  • Poor for small objects and frequent updates
  • More complex to build and operate

Trade-offs

ChoiceWe gainWe lose
Larger k, same mLower storage overheadMore pieces to read per repair, more failure domains needed
Larger m, same kSurvives more failuresMore space and more encode work
Erasure coding instead of copiesAbout half the space or lessCPU, repair traffic, slower degraded reads
Replicate hot, code coldFast reads for hot data and low cost for coldTwo systems and a migration step
LRC instead of Reed-SolomonCheaper single-piece repairA little more space, more complexity
Spread over zonesSurvives a zone lossCross-zone traffic costs and latency

10Common Problems and Mistakes

Common mistakes

  1. Putting pieces in the same failure domain. If three pieces share one rack and the rack fails, you lost three at once.
  2. Using it for small, hot objects. The pieces are tiny, so I/O costs dominate.
  3. Ignoring repair traffic. A node loss makes the cluster read k times more data than a copy-based design.
  4. Slow repair. The longer repair takes, the higher the chance that more than m pieces fail.
  5. Too few failure domains. A 12+4 layout needs at least 16 separate domains to use them well.
  6. Updating objects in place. Changing one cell means recomputing parity (a read-modify-write). Prefer write-once data.
  7. Assuming independent failures. The probability maths assumes disks fail on their own. A bad batch or a power event breaks that.

Things to watch

🧮CPU cost
Modern CPUs have vector instructions (such as Intel ISA-L) that make coding fast, but it still counts.
🌊Repair storms
After a big failure, repair traffic can slow user reads. Throttle it, but not too much.
🐢Tail latency
A read waits for the slowest of k pieces, unless you read extra pieces and use the first k.
🕳️Silent corruption
Add checksums per piece, so a corrupted piece is treated as an erasure.

11Real-World Examples

🪣Cloud object stores
Big providers do not publish every detail, but erasure coding across devices and zones is the standard way to get very high durability at low cost.
🐘Hadoop 3 (HDFS)
Supports policies such as RS-6-3-1024k, cutting the cost of cold data from 3x to 1.5x.
🔷Azure Storage
Uses local reconstruction codes (LRC) for cheaper repair, described in a published paper.
🧲Ceph and MinIO
Offer erasure coded pools and buckets, with configurable k and m.
📘Facebook (Meta)
Published work on HDFS RAID and f4 warm storage, using Reed-Solomon and later XOR across data centres for warm blobs.
💽RAID 5 and RAID 6
Disk arrays use XOR parity and a second parity to survive one or two disk failures.
📝Note
Exact layouts and numbers differ by product and version. The k, m and overhead figures here are well-known examples, not a complete list.
Mini case: warm data goes from 3 copies to 6+3
🔥New data3 copies, fast reads
→↓30 days later
⚙️Re-encode jobmakes 6+3
→↓delete copies
🧊Cold data1.5x space
Hot, replicated Cold, erasure coded
After a few weeks data is read less, so a background job re-encodes it and frees about half the space.

12Related Topics to Read Next

Object Storage→

The most common user of erasure coding.

Distributed File Systems→

HDFS and others offer erasure coded directories.

Replication→

The simple alternative: full copies.

Block Storage→

Volumes are often protected by copies or codes below the surface.

Checksums→

Detect damaged pieces so they can be treated as erasures.

Availability→

Durability and availability are different, and both matter.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • ✔What: k data + m parity pieces on different disks. Any k rebuild the data.
  • ✔Survives: up to m lost pieces. Lose m + 1 and data is gone.
  • ✔Space: (k + m) / k. 6+3 = 1.5x vs 3x for three copies.
  • ✔Intuition: XOR parity: P = A xor B xor C. Rebuild any one from the rest.
  • ✔Real code: Reed-Solomon (any k of k + m). LRC for cheaper repair.
  • ✔Costs: CPU, repair reads k pieces, slower degraded reads, poor for small objects.
  • ✔Spread: pieces across failure domains: disks, racks, zones.
  • ✔One line: “Same safety as copies, about half the space, paid for with maths and repair traffic.”
← Previous
Object Storage
Next →
Storage Tiers (Hot, Warm, Cold)