Erasure coding, replication and durability
How storage survives failures for less than three copies: a Reed-Solomon coder built and tested in C#, the cost of repair, durability computed from failure and repair rates, and reading the first k fragments to cut the tail.
ConceptCore23 min readUpdated
- 5 code samples
- 6 interviewer follow-ups
- 4 self-checks
On this page12 sectionsHLDLLDSenior depth
Read first: Storage engines and indexes
- Explain how k data and m parity fragments tolerate m losses at an overhead of (k + m) / k, and why any k fragments rebuild the data.
- Implement a Reed-Solomon coder over GF(256) and state what a repair costs in reads.
- Compute durability from failure and repair rates, and explain why the repair time raised to the number of parities sets the nines.
- Cut tail latency by reading more fragments than needed and using the first k to arrive.
5 code samples (231 lines), collapsed so the explanation stays in focus.
Disks fail. A large fleet loses some every day, and the classic defence is replication: keep three copies on different machines and any two can die. It works, and it costs three times the disks, the power and the network. Erasure coding gives the same kind of protection for about half the space: a 6+3 code stores 1.5 times the data and survives any three losses. Object stores, HDFS and archives use it, and a senior storage round will ask how it works and what it costs. This lesson builds a coder, measures what repair costs, computes durability from failure and repair rates, and shows a benefit that surprises people: reads can get faster.
Replication tolerates n - 1 losses with n copies, at n times the space. Parity does better. Take two data blocks A and B and store a third block P = A XOR B. Any one of the three is the XOR of the other two, so any single loss is survivable, at 1.5 times the space (RAID 5 is this idea with k blocks and one parity block). To survive m losses you need m parity blocks that are independent: no loss of m blocks may leave fewer than k independent equations for the k unknowns. Reed-Solomon codes provide exactly that, for any k and m, and no code does better: with m parity fragments you cannot survive more than m losses.
| Scheme | Fragments | Space used | Losses survived |
|---|---|---|---|
| 3 copies | 1 + 2 copies | 3.00x | 2 |
| RAID 5, 4+1 | 5 | 1.25x | 1 |
| 6+3 Reed-Solomon (HDFS's default erasure coding policy) | 9 | 1.50x | 3 |
| 10+4 (Facebook's f4 inside a data center) | 14 | 1.40x | 4 |
| 17+3 (Backblaze's storage vaults) | 20 | 1.18x | 3 |
| Local reconstruction code 12+2+2 (Azure) | 16 | 1.33x | Any 3, and some patterns of 4 |
The arithmetic must be exact, closed and invertible, so it uses a finite field. GF(256) treats a byte as a polynomial of degree below 8 over the two-element field, reduced modulo a fixed irreducible polynomial. Addition is XOR. Multiplication and division use logarithm tables, because every nonzero element is a power of a generator. Each fragment is then a weighted sum of the data fragments, byte by byte. The weights form a Cauchy matrix, entry (i, j) being 1 / (x_i + y_j) with every x and y distinct, and every square submatrix of a Cauchy matrix is invertible, which is the independence the code needs. Decoding picks any k surviving fragments, takes the matching k rows of the encoding matrix (the first k rows are the identity, so data fragments are stored as they are), inverts that k by k matrix by Gauss-Jordan elimination over GF(256), and multiplies it by the surviving fragments. Below is a complete coder. Plank's tutorial (in the sources) is the classic account for implementers.
C# · Arithmetic in GF(256): a byte is a polynomial over {0, 1} reduced modulo x^8 + x^4 + x^3…
using System;
using System.Linq;
// Arithmetic in GF(256): a byte is a polynomial over {0, 1} reduced modulo x^8 + x^4 + x^3 + x^2 + 1. Addition is XOR.
public static class Gf256
{
private static readonly byte[] Exp = new byte[512];
private static readonly int[] Log = new int[256];
static Gf256()
{
int x = 1;
for (int i = 0; i < 255; i++)
{
Exp[i] = (byte)x; Log[x] = i;
x <<= 1;
if ((x & 0x100) != 0) x ^= 0x11D;
}
for (int i = 255; i < 512; i++) Exp[i] = Exp[i - 255];
}
public static byte Mul(byte a, byte b) => a == 0 || b == 0 ? (byte)0 : Exp[Log[a] + Log[b]];
public static byte Inverse(byte a) => Exp[255 - Log[a]];
}
// A systematic Reed-Solomon code: k data shards plus m parity shards, and any k of the n = k + m shards rebuild the data.
public sealed class ReedSolomon
{
private readonly int k, m;
private readonly byte[][] matrix; // n rows of k coefficients; the first k rows are the identity
public ReedSolomon(int dataShards, int parityShards)
{
k = dataShards; m = parityShards;
matrix = new byte[k + m][];
for (int i = 0; i < k; i++) { matrix[i] = new byte[k]; matrix[i][i] = 1; }
// The parity rows are a Cauchy matrix: entry (i, j) is 1 / (x_i + y_j) with every x and y distinct. That makes
// every choice of k rows of the whole matrix invertible, which is what lets any k shards rebuild the data.
for (int i = 0; i < m; i++)
{
matrix[k + i] = new byte[k];
for (int j = 0; j < k; j++) matrix[k + i][j] = Gf256.Inverse((byte)((k + i) ^ j));
}
}
// Shard r is the dot product of row r with the data shards, byte by byte.
public byte[][] Encode(byte[][] data)
{
var shards = new byte[k + m][];
for (int r = 0; r < k + m; r++)
{
shards[r] = new byte[data[0].Length];
for (int c = 0; c < k; c++)
for (int b = 0; b < data[0].Length; b++) shards[r][b] ^= Gf256.Mul(matrix[r][c], data[c][b]);
}
return shards;
}
// Given at least k surviving shards (null marks a lost one), rebuild the data shards.
public byte[][] Decode(byte[][] shards)
{
var rows = Enumerable.Range(0, k + m).Where(r => shards[r] != null).Take(k).ToArray();
if (rows.Length < k) throw new InvalidOperationException("fewer than k shards survive");
var inverse = Invert(rows.Select(r => matrix[r]).ToArray());
var data = new byte[k][];
for (int d = 0; d < k; d++)
{
data[d] = new byte[shards[rows[0]].Length];
for (int c = 0; c < k; c++)
for (int b = 0; b < data[d].Length; b++) data[d][b] ^= Gf256.Mul(inverse[d][c], shards[rows[c]][b]);
}
return data;
}
// Gauss-Jordan elimination over GF(256).
private static byte[][] Invert(byte[][] source)
{
int n = source.Length;
var a = source.Select((row, i) => row.Concat(Enumerable.Range(0, n).Select(j => (byte)(i == j ? 1 : 0))).ToArray()).ToArray();
for (int col = 0; col < n; col++)
{
int pivot = col;
while (a[pivot][col] == 0) pivot++;
(a[col], a[pivot]) = (a[pivot], a[col]);
byte inverse = Gf256.Inverse(a[col][col]);
for (int j = 0; j < 2 * n; j++) a[col][j] = Gf256.Mul(a[col][j], inverse);
for (int row = 0; row < n; row++)
{
if (row == col || a[row][col] == 0) continue;
byte factor = a[row][col];
for (int j = 0; j < 2 * n; j++) a[row][j] ^= Gf256.Mul(factor, a[col][j]);
}
}
return a.Select(row => row.Skip(n).ToArray()).ToArray();
}
}C# · 6 data shards and 3 parity shards: 1.5 times the data in storage, and any 3 shards can…
using System;
using System.Diagnostics;
using System.Linq;
// 6 data shards and 3 parity shards: 1.5 times the data in storage, and any 3 shards can be lost.
var coder = new ReedSolomon(6, 3);
var shardRandom = new Random(4);
var original = Enumerable.Range(0, 6).Select(_ => { var shard = new byte[1_000]; shardRandom.NextBytes(shard); return shard; }).ToArray();
var stored = coder.Encode(original);
Debug.Assert(Enumerable.Range(0, 6).All(i => stored[i].SequenceEqual(original[i]))); // systematic: the data shards are stored as they are
int rebuiltCases = 0, lostCases = 0;
for (int lostMask = 0; lostMask < 1 << 9; lostMask++) // every possible set of lost shards
{
int lost = 0;
for (int bits = lostMask; bits != 0; bits &= bits - 1) lost++;
var survivors = stored.Select((shard, i) => (lostMask >> i & 1) == 1 ? null : shard).ToArray();
if (lost > 3)
{
Debug.Assert(Throws(() => coder.Decode(survivors))); // four losses cannot be repaired
lostCases++;
continue;
}
var rebuilt = coder.Decode(survivors);
Debug.Assert(Enumerable.Range(0, 6).All(i => rebuilt[i].SequenceEqual(original[i])));
rebuiltCases++;
}
Debug.Assert(rebuiltCases == 1 + 9 + 36 + 84 && lostCases == 512 - 130);
bool Throws(Action action) { try { action(); return false; } catch (InvalidOperationException) { return true; } }The test encodes six random data fragments into nine, then loses every possible set of fragments. All 130 patterns of three or fewer losses (1 + 9 + 36 + 84) were rebuilt exactly, and each of the 382 patterns with four or more losses was refused, because fewer than six fragments survive. The code is systematic: the first six fragments are the data itself, so a healthy read needs no decoding.
- Repair reads k fragments to rebuild one. Rebuilding 1 TB of lost fragments in 6+3 reads 6 TB, where a lost replica needs one copy read. Repair traffic is the price of the cheaper storage. Microsoft's Local Reconstruction Codes add local parities so that one lost fragment needs half the reads, for the same space and a little less worst-case tolerance: in 12+2+2 (12 data fragments, 2 local and 2 global parities, 1.33 times) a single-fragment repair reads 6 fragments, where a 12+4 Reed-Solomon code at the same space reads 12 and tolerates any four losses.
- Updates rewrite the stripe. Changing one byte changes every parity fragment. That is fine for immutable objects and a reason systems write a new stripe and commit it, instead of editing in place.
- Reads touch more nodes. A read contacts k nodes instead of one. Done naively that raises tail latency, and done well (below) it lowers it.
- Small objects do not stripe well. A 4 KB object in 6+3 becomes nine tiny fragments. Replicate small objects, or pack many into one container.
- Wider stripes save space and cost more. 17+3 uses 1.18 times the data against 1.5 for 6+3, but a repair reads 17 fragments, a read touches 17 nodes, and each stripe needs 20 failure domains.
- CPU. Encoding and decoding are table lookups and XORs on bytes. Real coders (Backblaze open-sourced one, and Intel's ISA-L and Jerasure are widely used) use vector instructions and run near memory speed.
A stripe of n fragments is lost when more than m are missing at once. Each disk fails at some rate and each missing fragment is rebuilt after some time, so the question is how likely it is that more than m failures overlap inside repair windows. Model it: each disk fails at λ per year, each missing fragment is rebuilt after an exponentially distributed time with mean R, rebuilds run in parallel, and failures are independent. The number of missing fragments is then a birth-death chain, and the mean time until it reaches m + 1 is a sum of positive terms (so it stays accurate when it is astronomically large). The code below computes it, and also simulates the stripe fragment by fragment, as an independent check.
C# · Durability
using System;
public static class Durability
{
// A stripe is n fragments on n independent disks, and it survives while at most m of them are missing at once.
// A disk fails at `failuresPerYear` (exponentially distributed); a missing fragment is rebuilt after an exponentially
// distributed time with mean `repairYears`, and all rebuilds run in parallel. The state is the number of missing
// fragments, from 0 to m, and the stripe is lost on the failure that makes it m + 1. This is a birth-death chain, and the
// mean time to reach the loss state is a sum of positive terms (so it stays accurate even when it is astronomically large):
// T = sum over j of (rho_0 + ... + rho_j) / (b_j * rho_j), b_j = (n - j) * failure rate,
// rho_j = product of b_(k-1) / d_k for k = 1..j, d_k = k * repair rate
public static double MeanYearsToLoss(int n, int m, double failuresPerYear, double repairYears)
{
double repairsPerYear = 1 / repairYears, rho = 1, running = 0, total = 0;
for (int j = 0; j <= m; j++)
{
if (j > 0) rho *= (n - (j - 1)) * failuresPerYear / (j * repairsPerYear);
running += rho;
total += running / ((n - j) * failuresPerYear * rho);
}
return total;
}
// The same stripe, simulated one fragment at a time: each fragment has its own failure timer, and each missing one its
// own rebuild timer. It checks the formula by a different route.
public static double SimulatedYearsToLoss(int n, int m, double failuresPerYear, double repairYears, int trials, int seed)
{
var random = new Random(seed);
double Exponential(double mean) => -mean * Math.Log(1 - random.NextDouble());
double sum = 0;
for (int trial = 0; trial < trials; trial++)
{
var nextEvent = new double[n];
var missing = new bool[n];
for (int i = 0; i < n; i++) nextEvent[i] = Exponential(1 / failuresPerYear);
int down = 0;
double now;
while (true)
{
int who = 0;
for (int i = 1; i < n; i++) if (nextEvent[i] < nextEvent[who]) who = i;
now = nextEvent[who];
if (missing[who]) { missing[who] = false; down--; nextEvent[who] = now + Exponential(1 / failuresPerYear); }
else
{
missing[who] = true;
if (++down > m) break;
nextEvent[who] = now + Exponential(repairYears);
}
}
sum += now;
}
return sum / trials;
}
}C# · The formula against a simulation with exaggerated numbers: disks that fail twice a year…
using System;
using System.Diagnostics;
// The formula against a simulation with exaggerated numbers: disks that fail twice a year and take about a month to rebuild.
double formula = Durability.MeanYearsToLoss(5, 2, 2.0, 0.08);
double simulation = Durability.SimulatedYearsToLoss(5, 2, 2.0, 0.08, 20_000, 1);
Debug.Assert(Math.Abs(simulation / formula - 1) < 0.03);
// Realistic numbers: disks that fail 2% of the time each year, with fragments rebuilt in 1 day or in 7 days.
const double diskFailuresPerYear = 0.02;
double AnnualLoss(int n, int m, double repairDays) => 1 / Durability.MeanYearsToLoss(n, m, diskFailuresPerYear, repairDays / 365.0);
var expectedLoss = new[]
{
(Name: "3 copies", N: 3, M: 2, OneDay: 1.8e-10, SevenDays: 8.8e-9),
(Name: "6+3 erasure coding", N: 9, M: 3, OneDay: 1.7e-12, SevenDays: 5.7e-10),
(Name: "10+4 erasure coding", N: 14, M: 4, OneDay: 1.8e-15, SevenDays: 4.3e-12),
};
foreach (var scheme in expectedLoss)
{
Debug.Assert(Math.Abs(AnnualLoss(scheme.N, scheme.M, 1) / scheme.OneDay - 1) < 0.05);
Debug.Assert(Math.Abs(AnnualLoss(scheme.N, scheme.M, 7) / scheme.SevenDays - 1) < 0.05);
Debug.Assert(Math.Abs(AnnualLoss(scheme.N, scheme.M, 7) / AnnualLoss(scheme.N, scheme.M, 1) / Math.Pow(7, scheme.M) - 1) < 0.2); // loss grows as the repair time to the power m
}First the formula was checked against the simulation with exaggerated numbers (disks failing twice a year and taking about a month to rebuild): the formula gives a mean of 1.72 years to lose a 3+2 stripe and the simulation 1.71. Then realistic numbers: disks that fail 2% of the time each year (a little above the 1% to 2% that Backblaze's published drive statistics show for a large fleet), and fragments rebuilt in one day or in seven.
| Scheme | Space | Annual loss, 1-day repair | Annual loss, 7-day repair | Ratio |
|---|---|---|---|---|
| 3 copies | 3.00x | 1.8e-10 (9.7 nines) | 8.8e-9 (8.1 nines) | 49 |
| 6+3 erasure coding | 1.50x | 1.7e-12 (11.8 nines) | 5.7e-10 (9.2 nines) | 342 |
| 10+4 erasure coding | 1.40x | 1.8e-15 (14.7 nines) | 4.3e-12 (11.4 nines) | 2,388 |
Three lessons come out of the table.
- Erasure coding is cheaper and, with fast repair, safer. 6+3 uses half the disks of three copies and loses data about a hundred times less often, because it survives three simultaneous failures instead of two.
- Repair time is the lever. Loss probability grows as the repair time to the power m: a week instead of a day multiplies it by 7^m (49, 343 and 2,401, and the measured ratios match). A slow repair queue erases the benefit of more parity, so systems repair the most endangered stripes first, keep spare capacity for rebuilds and treat the repair backlog as a first-class metric.
- The model is an upper bound on safety. Amazon states that S3 is designed for 99.999999999% (11 nines) durability of objects over a year, and the model gives 9 to 15 nines for independent disks. Real failures are not independent. Google's study of its storage fleet found that bursts of failures and the loss of a whole rack or power domain dominate unavailability, and that extra replicas help less once failures are correlated. Real durability is limited by correlated failures, software bugs and operator error, so the defences are to spread fragments over disks, machines, racks and zones, to roll out software in stages, to scrub for silent corruption, and to offer versioning and delete protection against human mistakes.
A read needs any k fragments, not particular ones. That turns a cost into an advantage. Reading exactly the k data fragments waits for the slowest of k reads, so the tail-latency arithmetic of tail latency and overload applies. Ask for more fragments than you need and use the first k to arrive, and a slow fragment simply loses the race.
C# · Reading an object stored as 6 data and 3 parity shards. A shard read takes a lognormal…
using System;
using System.Diagnostics;
using System.Linq;
// Reading an object stored as 6 data and 3 parity shards. A shard read takes a lognormal time (median 10 ms), and one read in
// fifty also hits a stall that adds 200 ms (a busy disk, a garbage collection, a retransmission).
var readRandom = new Random(5);
double ShardRead()
{
double normal = Math.Sqrt(-2 * Math.Log(1 - readRandom.NextDouble())) * Math.Cos(2 * Math.PI * readRandom.NextDouble());
return 10 * Math.Exp(0.5 * normal) + (readRandom.NextDouble() < 0.02 ? 200 : 0);
}
double Percentile(double[] sorted, double p) => sorted[(int)(p * (sorted.Length - 1))];
const int objectReads = 200_000;
var sixShards = new double[objectReads]; var sevenShards = new double[objectReads]; var nineShards = new double[objectReads];
for (int i = 0; i < objectReads; i++)
{
var shardTimes = Enumerable.Range(0, 9).Select(_ => ShardRead()).ToArray();
sixShards[i] = shardTimes.Take(6).Max(); // read the 6 data shards and wait for all of them
sevenShards[i] = shardTimes.Take(7).OrderBy(t => t).ElementAt(5); // read 7 shards and use the first 6 to arrive
nineShards[i] = shardTimes.OrderBy(t => t).ElementAt(5); // read all 9 and use the first 6 to arrive
}
foreach (var times in new[] { sixShards, sevenShards, nineShards }) Array.Sort(times);
Debug.Assert(Percentile(sixShards, 0.5) > 18 && Percentile(sixShards, 0.5) < 22 && Percentile(sixShards, 0.99) > 200 && Percentile(sixShards, 0.99) < 240);
Debug.Assert(Percentile(sevenShards, 0.5) > 13 && Percentile(sevenShards, 0.5) < 17 && Percentile(sevenShards, 0.99) > 35 && Percentile(sevenShards, 0.99) < 45 && Percentile(sevenShards, 0.999) > 150);
Debug.Assert(Percentile(nineShards, 0.5) > 10 && Percentile(nineShards, 0.5) < 14 && Percentile(nineShards, 0.99) > 17 && Percentile(nineShards, 0.99) < 24 && Percentile(nineShards, 0.999) < 30);The model gives each fragment read a lognormal time with a median of 10 ms, and one read in fifty a stall that adds 200 ms (a busy disk, a garbage collection, a retransmission). Over 200,000 object reads of a 6+3 object:
| Read | Extra bytes read | p50 | p99 | p99.9 |
|---|---|---|---|---|
| The 6 data fragments, waiting for all | none | 20 ms | 220 ms | 233 ms |
| 7 fragments, first 6 to arrive | 1.17x | 15 ms | 40 ms | 212 ms |
| All 9 fragments, first 6 to arrive | 1.5x | 12 ms | 20 ms | 24 ms |
The stalls are invisible at the median and ruin the tail: waiting for six fragments, 11% of reads meet at least one stall, so the p99 is 220 ms. One extra fragment (17% more bytes) cut the p99 to 40 ms, and reading all nine (50% more bytes) cut it to 20 ms. The price is extra load on the nodes, which a busy cluster may not have, and the numbers depend on the assumed distribution, so measure yours.
| Replication | Erasure coding | |
|---|---|---|
| Space | 2x to 3x | 1.2x to 1.5x |
| Repair | Reads one copy | Reads k fragments (less with local codes) |
| Read | One node | k nodes, with the tail-latency trick above |
| Small objects | Natural | Pack them or replicate them |
| In-place updates | Fine | Rewrites the stripe |
| Typical use | Hot and small data, metadata, logs in flight | Large, cold or immutable data |
Systems mix them and move data between them. In Facebook's f4, a paper on warm BLOB storage, replication of 3.6 times came down to 2.8 or 2.1 times with Reed-Solomon inside a data center and an XOR code across data centers. HDFS offers both, with 3 copies as the long-standing default (200% overhead) and a 6+3 policy at 50%.
| Case | What goes wrong | Response |
|---|---|---|
| Failures are correlated | More fragments vanish together than the model assumes | Spread fragments over racks and zones, use no more fragments than domains |
| Repair is slow | The window for overlapping failures grows as the repair time to the power m | Repair by risk, keep spare capacity, alert on the backlog |
| Silent corruption | A fragment returns wrong bytes without an error | Checksums per fragment, scrubbing, treat a mismatch as a lost fragment |
| Two fragments share a rack | One rack failure spends several of the m losses | Place by failure domain, not by free space alone |
| A crash during a stripe write | Some fragments are new and some old | Write a new stripe and commit it atomically, never update in place |
| A data fragment is lost | Reads must decode until repair finishes | Repair promptly, read more fragments than needed |
| Small objects | Striping multiplies overhead | Replicate, or pack many objects into one |
| Mixed code parameters | The wrong decoder is applied | Record the scheme in each object's metadata |
Interviewer follow-upL5What is erasure coding, and how does it compare with replication?How to answer
Split data into k fragments, compute m parity fragments, store all k + m on different failure domains, and any k rebuild the data, so any m losses are survivable at (k + m) / k of the space. Three copies cost 3 times the space for two survivable losses. A 6+3 code costs 1.5 times for three. The price is repair traffic (k fragments read to rebuild one), more nodes per read, and trouble with small objects and in-place updates.
Interviewer follow-upL5How many failures does a 10+4 code tolerate, and what is its overhead?How to answer
Any four, at 14 / 10 = 1.4 times the data. No code with four parity fragments can survive more than four losses. Five losses leave nine fragments, fewer than the ten needed to rebuild.
Interviewer follow-upL6Why does repair time matter more for erasure-coded data?How to answer
Data is lost when more than m fragments are missing at once, so the loss probability grows with the repair window to the power m. For three copies that is the square, for 6+3 the cube. A week instead of a day multiplies the loss rate by 49 for three copies and by 343 for 6+3 in the model. More parity gives more tolerance only if repair keeps pace.
Interviewer follow-upL6A disk holding one fragment of each of many 6+3 stripes dies. What does the repair read and write?How to answer
For each stripe the repair reads six surviving fragments and writes one rebuilt fragment to another disk in a different failure domain, so six times the lost data is read across the cluster. It is rate-limited to protect client traffic and ordered by how few fragments a stripe has left. A local reconstruction code would halve the reads for a single loss.
Interviewer follow-upL7How would you reduce repair traffic?How to answer
Use a code with local parities (Azure's 12+2+2 repairs one fragment from 6 reads instead of 12), keep the fragments of a local group in one rack so repair reads stay off the core network, repair by risk so that the most endangered stripes go first, and consider replicating the hottest data, which is cheap to repair. Accept that every saving in repair traffic costs some space or some tolerance.
Interviewer follow-upL7How would you test an erasure coder?How to answer
Exhaustively for small codes, as the sample does: every pattern of up to m losses must rebuild exactly and every worse pattern must be refused. Property-test random data, lengths and loss patterns for larger codes. Cross-check against a reference implementation such as Jerasure or ISA-L, test corrupted fragments (a mismatch must be detected, because the code cannot tell a bad fragment from a good one), and test that decoding works when the lost fragments are the data fragments.
Say what you trade: space for repair traffic and complexity. Give the arithmetic: any k of n fragments rebuild the data, 6+3 is 1.5 times the space for three losses. Say what decides durability: the repair time to the power m, with failures spread over racks and zones because real failures are correlated. And mention the tail: reading more than k fragments and using the first k.
Erasure coding stores k data fragments and m parity fragments, any k of which rebuild the data, so any m losses are survivable at (k + m) / k of the space. Reed-Solomon over GF(256) does it with a Cauchy matrix and a matrix inverse: the tested coder rebuilt all 130 loss patterns of up to three in 6+3 and refused all 382 worse ones. A repair reads k fragments to rebuild one, which local reconstruction codes halve at some cost in space. Durability is a race between failures and repair: 6+3 with day-long repair loses a stripe about a hundred times less often than three copies at half the space, the loss probability grows with the repair time to the power m, and the model is an upper bound because real failures are correlated. A read can ask for more than k fragments and use the first k: one extra fragment cut the p99 from 220 ms to 40 ms for 17% more bytes.
Try answering out loud before you reveal each answer.
QuestionIn a 6+3 erasure-coded stripe, how many fragments can be lost, why, and what does repairing one read?Reveal answer
Any three. The code makes every set of six of the nine fragments independent, so any six rebuild the data, and with four lost only five remain. Repairing one lost fragment reads six surviving fragments, so repair traffic is six times the lost data, where a lost replica needs one copy read.
QuestionRepair takes seven days instead of one. How does the annual loss probability of a 6+3 stripe change, and why?Reveal answer
It grows by about 7 to the power 3, roughly 343 times (1.7e-12 to 5.7e-10 in the model). Data is lost when four fragments are missing at once, and the chance that three more fail within the repair window of the first grows with the window to the power of three. That is why repair speed and the repair backlog are durability metrics.
QuestionWhy does reading seven of nine fragments cut the tail latency of a 6+3 read?Reveal answer
A read needs any six fragments, so asking for seven and using the first six to arrive means a single slow fragment no longer delays the request: it is slow only if two of the seven are slow. In the simulation the p99 fell from 220 ms to 40 ms for 17% more bytes read, and the cost is extra load on the nodes.
QuestionA 6+3 stripe puts three fragments in each of three racks. What is wrong with that?Reveal answer
A single rack failure removes three fragments, which spends the whole tolerance of the code, so any further failure before repair loses data. Place each fragment in a different rack (nine racks), or choose a code whose parameters fit the domains. The independence assumed in the durability model only holds across independent failure domains.
- James S. Plank, A Tutorial on Reed-Solomon Coding for Fault-Tolerance in RAID-like Systems (opens in a new tab), Software: Practice and Experience, 1997: the implementer's account (read it with the later correction note from the same page).
- Cheng Huang and others, Erasure Coding in Windows Azure Storage (opens in a new tab), USENIX ATC 2012: Local Reconstruction Codes and repair cost.
- Subramanian Muralidhar and others, f4: Facebook's Warm BLOB Storage System (opens in a new tab), OSDI 2014: Reed-Solomon and XOR coding in production.
- Daniel Ford and others, Availability in Globally Distributed Storage Systems (opens in a new tab), OSDI 2010: correlated failures in a production storage fleet.
- Apache Hadoop, HDFS Erasure Coding (opens in a new tab): policies, the default RS-6-3 policy and its overhead. Backblaze, Resiliency, Durability and Availability (opens in a new tab): 17 data and 3 parity fragments across 20 servers.
- Backblaze, Drive Stats (opens in a new tab): published annualised failure rates of a large disk fleet. Amazon Web Services, Data protection in Amazon S3 (opens in a new tab): the 11-nines design target.