Full answer
Replication
Store 3 full copies on different machines or zones. Survives 2 failures, reads from any copy are cheap, and repairing a lost copy means copying one replica. Storage overhead: 3x.
Erasure coding
Split a chunk into k data fragments, compute m parity fragments, store all k + m on different failure domains. Any k fragments reconstruct the chunk.
The simplest case is k data fragments plus one XOR parity fragment (m = 1), like RAID 5:
from functools import reduce
def xor_bytes(blocks):
return bytes(reduce(lambda x, y: x ^ y, col) for col in zip(*blocks))
if __name__ == "__main__":
data = [b"lesson01", b"lesson02", b"lesson03", b"lesson04"] # 4 data fragments
parity = xor_bytes(data) # 1 parity fragment
lost = 2
survivors = [blk for i, blk in enumerate(data) if i != lost] + [parity]
rebuilt = xor_bytes(survivors)
assert rebuilt == data[lost]
print("ok: rebuilt", rebuilt.decode(), "| overhead", (len(data) + 1) / len(data))Save as xor_parity.py and run python3 xor_parity.py (Python 3.13.5).
Reed-Solomon codes generalise this to any m, for example:
- 6 + 3: overhead 9 / 6 = 1.5x, survives 3 losses.
- 10 + 4: overhead 1.4x, survives 4 losses.
Comparing at 1 PB of data
| Scheme | Raw storage | Failures survived |
|---|---|---|
| 3 replicas | 3 PB | 2 |
| RS 6 + 3 | 1.5 PB | 3 |
| RS 10 + 4 | 1.4 PB | 4 |
Erasure coding gives both higher fault tolerance and half the storage of replication.
The costs
- Repair bandwidth. Rebuilding one lost 64 MB fragment in 6 + 3 reads 6 fragments (384 MB) across the network, versus 64 MB for replication. When a 20 TB disk fails, repair traffic is large. Locally repairable codes (used in Azure storage) add local parity groups so most repairs read fewer fragments.
- Latency. A read must contact k nodes and wait for all of them (or decode from parity when one is slow), and small objects fragmented into tiny pieces are inefficient. Systems pack small objects into large chunks first.
- CPU for encoding and decoding, modest with modern instruction sets.
- Writes need all fragments (or enough of them) to be stored before acknowledging.
Durability depends on repair speed
Data is lost only if more than m fragments of the same chunk fail before repair finishes. Fast failure detection, spreading fragments across racks and zones, and quick parallel repair matter as much as the code parameters.
When to use which
- Replication: small objects, hot data with heavy reads, low-latency needs, metadata.
- Erasure coding: large objects, warm and cold data, archives, most bytes in object stores.
- Many systems write new data replicated and convert it to erasure-coded form once it cools down.
By level
Fresher: Explain that extra parity pieces let you rebuild lost pieces, using the XOR example. A fresher should compare the storage used with keeping three copies.
Mid: Compare replication and Reed-Solomon codes on storage, failures survived, repair and latency. Explain packing small objects.
Senior: Discuss locally repairable codes, durability modelling with repair time, failure domains, tiering from replicated to coded data and read latency strategies. Expect numbers behind each claim.
Key points
- Any k of k + m fragments rebuild the data
- RS 6 + 3 survives 3 losses at 1.5x storage; 3 replicas survive 2 at 3x
- Repairs read k fragments, so repair bandwidth is high
- Small objects are packed before coding
- Durability depends on fast detection and repair
Common mistakes
- Assuming erasure coding is always better than replication
- Ignoring repair bandwidth after large disk failures
- Placing several fragments in the same failure domain
- Erasure coding tiny objects one by one
Follow-ups
- What are locally repairable codes?
- How would you calculate the probability of data loss?
- Why convert data from replicated to erasure-coded form over time?
Tips
- Do the storage comparison table
- Explain the XOR example first
- Raise repair cost before being asked
Evaluation rubric
- Correct explanation of k + m coding
- Accurate cost and durability comparison
- Repair and latency trade-offs
- Sensible usage guidance