Skip to content
System Design Explorer
storage

Erasure Coding

By Ankur NayakReviewed

Erasure coding protects data by splitting it into k data shards and computing m extra parity shards, so the original can be rebuilt from any k of the k + m shards. It survives the loss of m disks for far less extra storage than keeping full copies, which is why large object stores use it.

Erasure Coding diagramComponents: Client, Encoder, Disks (data shards), Disks (parity shards). Connections: Client to Encoder (PUT); Encoder to Disks (data shards) (k shards); Encoder to Disks (parity shards) (m parity).ClientClientEncoderServiceDisks (data shards)Object storageDisks (parity shards)Object storage
Writing an object as k + m shards

How it works

With Reed-Solomon coding, a file is cut into k equal data shards and m parity shards are computed from them. Any k of the k + m shards are enough to reconstruct the file. Backblaze's example splits a file into 17 data shards plus 3 parity shards: any 17 of the 20 pieces rebuild the original, so three can be lost.

Compared with replication, the saving is large. Three full copies cost 3x the data and survive two losses; a 17 + 3 code costs about 1.18x and survives three. The price is computation and more machines involved in each read and repair.

Placement matters as much as the code. Amazon S3 erasure-codes objects and deliberately spreads different objects across different sets of drives, so each object's shards land on independent disks and a burst of requests for one customer's data is served by many disks at once: in 2023 Andy Warfield described a single burst served by over a million disks.

Key points

  • k data shards + m parity shards; any k rebuild the data
  • Tolerates m lost shards
  • Overhead (k + m) / k, far below 3x replication
  • Spread shards across independent disks, racks and zones
  • Repairs read k shards to rebuild one

When to use it, and pitfalls

Use it for

  • Large object and blob stores
  • Cold and archival storage
  • Any system storing far more bytes than it serves per second

Watch out for

  • Small objects: per-shard overhead and many tiny writes; pack them first
  • Repairs are expensive: rebuilding one shard reads k others
  • Latency-sensitive hot data may still prefer replicas for fast single reads

Trade-offs

Erasure coding vs. replication

Erasure-code bulk data; replicate small, hot or latency-critical data.

Pros: Much lower storage overhead for the same or better durability

Cons: CPU for encoding and decoding; Reads and repairs touch more machines

Used in

Frequently asked questions

How is erasure coding different from replication?

Replication stores full copies; three copies cost three times the data and survive two losses. Erasure coding stores k data shards plus m parity shards, any k of which rebuild the data, so a 17 + 3 code survives three losses for about 1.18 times the data.

Why don't all databases use erasure coding?

Reading or repairing erasure-coded data involves several machines and some computation, which adds latency. Hot, small or latency-critical data is often still replicated; erasure coding pays off for large volumes of data such as objects and archives.

Sources