Ch.29: System Design: How Object Storage Survives a Lost Zone
Outline
- 0:00 Upload success, then a zone goes dark
- 0:27 Two paths behind one object key
- 1:03 What success must mean
- 2:00 Bytes first, visibility second
- 3:02 The cost of three full copies
- 3:53 How parity recovers missing fragments
- 5:20 Failure domains decide what survives
- 6:12 Checksums detect, redundancy recovers
- 7:20 Keep a download on one version
- 8:12 Metadata must survive too
- 9:16 Old reads work, new success can wait
- 10:22 Repair races and failure margin
- 11:49 Cleanup, leases and tombstones
- 13:04 Follow the complete download path
- 14:00 What to measure beyond healthy requests
Transcript
0:00 Nia uploads the only copy of a 4-gigabyte film. Our fictional object storage service, Harbor Store, says success. Then an entire storage zone goes dark. What does that success actually promise her? I think that success has to mean she can download her film without waiting for that zone to come back. Right. We'll separate the failure locations, store recovery information with the film, and make sure the record that finds those bytes survives too. Let's follow her upload through the map. Nia reaches an authorization gateway.
0:31 Her upload goes through an encoder into storage nodes spread across three zones. Where does the name of her film go? Into replicated metadata. That record identifies the exact object version and its pieces. For her download, the reader retrieves that record and rebuilds her film from pieces it has checked. And these background workers check stored pieces and replace missing ones. The upload path puts recovery information there; the repair path keeps it useful. Yes. What are we committing to when Nia receives that success response?
1:02 Let's make Nia's success promise precise. Our functional requirements are four operations. First, store a whole version. Second, download it, including selected byte ranges. 3rd, list committed keys, so she can find her completed uploads. 4th, overwrite or delete a key atomically. A reader sees one complete version, never half the old film glued to half the new one. Every operation checks the tenant's permission. For the non-functional requirements, an acknowledged film must survive a lost zone, with its metadata recoverable too.
1:35 Committed changes must be visible immediately. Storage and repair costs must stay bounded. We're staying within one region. So a region-wide disaster is outside this contract. And surviving one zone doesn't mean we can keep losing hardware indefinitely. Agreed. We'll have a finite safety margin, and restoring it is part of operating the service. Now, what must happen before we tell Nia her film is stored? Start with a fresh immutable generation, meaning one version whose bytes never change. The storage nodes write and verify its pieces, then return durable receipts.
2:10 We check the required placement before publishing its metadata. Right, that's the moment her film becomes findable. If we commit that record first and crash before the bytes land, Nia gets a successful upload pointing at missing content. Yep. AWS and Google's storage documentation both describe redundant storage before acknowledgement. Our design applies that principle: required pieces first, durable metadata commit next, success last. Their exact layouts differ from ours; source links are in the description.
2:38 Suppose the process dies before that commit. There might be stored pieces with no visible film, but we haven't promised Nia a working object yet. Correct. We'll clean those up safely later. The committed record is a manifest: the generation, piece identities, checksums and locations needed to retrieve this film. That's quite a lot riding on one success response. How many bytes are we paying to make it honest? Now price that storage. For example, Nia's original needs 12 gigabytes if we store three entire copies, before metadata.
3:09 Each surviving copy serves the film directly. Harbor's storage lead might reasonably ask, 'Why run a decoder when a whole copy already works?' I'm with you on simplicity. At a huge stored volume, though, the extra capacity becomes a serious cost. We can divide the film into four equal data fragments and compute two same-sized recovery pieces called parity fragments. Each is 1 gigabyte in this toy example. 6 gigabytes stored instead of 12. So we halve the raw storage, while adding encoding and reconstruction work.
3:42 I'd like the smaller storage bill, though we'd be paying for it in reads and repairs. It's a storage factor of one and a half instead of three. What do those parity fragments contain? Let's unpack those extra pieces. Each contains a different mathematical mix of the original data. This is erasure coding. A suitable four-plus-two Reed-Solomon code recovers the film from any four of six verified fragments, even when original pieces are missing. I can picture adding recovery information. But why does any four work, rather than one particular set?
4:15 Think of four unknown byte values and six relationships describing them. The code chooses the mixes so any four give independent equations, enough to solve for the originals. It uses its own byte arithmetic, but that equation-solving idea is the mechanism. Ah, so the parity fragments aren't the last two scenes of the movie. They contain relationships that let us recover scenes in the missing data pieces. Backblaze's coding explanation shows this with a matrix. We're borrowing that recovery principle, without claiming our layout is how S3 works or calculates its durability target.
4:50 Suppose we lose one data fragment and one parity fragment. The other four still contain enough information. Losing two data fragments also works, with both parity fragments available. Yes. Implementation processes small stripes, meaning small groups of encoded pieces, and streams them through. We don't hold a 4-gigabyte video in memory just to perform the calculation. Then the code answers how many pieces we can lose. Placement decides whether one failure takes too many at once. Let's test that placement.
5:21 Imagine all six fragments sit on different drives in one rack. The rack loses power, and our clever code has no reachable input. Yeah, losing that rack defeats the layout. A failure domain is a group of resources one event can affect together. We place two fragments in every zone, and separate disks and nodes within each location. Take zone two offline. Its two fragments vanish from our available set. Four remain, exactly what the decoder needs. Yep. Nia can still read, but we've used the entire two-fragment margin.
5:53 Another unavailable piece means this object cannot currently be reconstructed. Oh, that changes the incident. “Still readable” sounds reassuring until you notice there's no spare piece left. This is when repair becomes urgent. It does. But first, we have to know whether those four surviving fragments contain the right bytes. Now check the surviving bytes. Each fragment has a checksum, a compact value calculated from its bytes and bound to its identity in the manifest. On a read, we verify it. Background checks also search for silent corruption.
6:25 For instance, Nia's storage node returns a full-length fragment with 1 changed bit. You open the request logs and see success. Yet the checksum tells our reader those bytes cannot be trusted. That's a familiar debugging trap: a successful response can contain the wrong data. Right. We reject those damaged bytes and try another verified piece, if one is available. Google documents proactive integrity checks and repair. S3 also supports checksum validation. If the lost zone has already removed two, that bad fragment leaves only three good ones online.
6:59 A checksum spots the damage, but it can't supply the missing gigabyte. Yes. We return an error until enough verified pieces are available. Sending a damaged film would violate the promise even if every HTTP request reported success. So identity matters as well as intact bytes. What happens if Nia uploads a new cut while the old one is downloading? For that overwrite case, consider a download split across several byte-range requests. The first range comes from generation one, then Nia overwrites the key.
7:30 Without a version constraint, later ranges could come from generation two. We pin the generation at download start. Its fragments stay immutable, and every range refers to that same identity. The new upload creates separate pieces before atomically moving the name to its new generation. That sounds like the difference between the film's name and the particular cut I'm watching. The name can move, but my download must stay on its chosen cut. Yes. Google warns about overwrites during a download. The bytes can change between requests, so our reader pins a generation and uses it for every range.
8:05 What happens if all those pieces survive, but the record connecting them to Nia's film is lost? Then Nia's film can become unusable. We may have all its bytes and no reliable way to locate, identify or assemble them. The metadata failure defeats the surviving fragments. We'd built a very expensive drawer full of unlabeled pieces. Replicating large objects doesn't protect the record that explains which pieces belong together. I'd dread that recovery job. We have all her bytes, and Nia's still waiting while we hunt for their labels.
8:38 Our metadata has one voting replica per zone. Two form a majority for current-state reads and commits. Recovery records preserve identities and placements; we test restoring them independently of the byte storage. A fragment scan might rebuild part of an inventory, but it can't magically recover a deleted filename or permission unless we preserved those facts somewhere. Exactly. Full copies make sense for this small metadata record. Coding tiny pointers would complicate the part of the system every read needs.
9:09 Now a zone can disappear and both paths still have survivors. Does that mean uploads continue normally too? But accepting new uploads is different. Nia's old film still has four good pieces online, and metadata has its majority. The download can proceed. But a new upload cannot meet our chosen requirement of six pieces in three independent zones. We refuse or wait until eligible placement is available, rather than acknowledge a weaker object under the same promise. That's a product decision I'd want explicit before an outage.
9:41 Reading an acknowledged object and accepting a new one have different conditions. I think the service needs separate read and write availability measures. We measure which requests work now. Even with intact pieces, an unreachable metadata majority can block either path. A projection room locked for tonight can cancel a screening without destroying its film. Likewise, a 3rd unavailable fragment stops our download now, but enough offline pieces might return. Yes. Durability asks whether enough information survives to recover the object.
10:12 Burn the only surviving film and no future screening is possible. In our code, three permanently destroyed distinct pieces leave too little information to reconstruct it. Now restore the lost zone's protection. We need that zone back or another independent eligible zone in the same region. A repair worker reads enough verified fragments to decode, reconstructs a missing piece, and writes it to eligible spare storage. It verifies the replacement before conditionally updating the placement record.
10:41 Conditionally, because another worker might already have repaired it or the object might have been deleted. An old job cannot blindly replace today's metadata. Exactly. We check that the object generation is still live and that its fragment-location record has the version we read. If either changed, our update is rejected. Readers keep using a valid placement during the transition. Yeah, and here's a practical failure case: the cluster runs nearly full. The film remains readable, but we have nowhere eligible to put the replacement.
11:11 The redundancy alarm won't repair itself. Right. Paging us again won't create an eligible disk. Reserve space in eligible failure domains and prioritize exposed objects. Extra disks in just the two surviving zones cannot restore our three-zone promise. Limit repair traffic so recovery doesn't starve downloads. I can picture that queue now. Her download works, but the film stays exposed until we've verified the missing pieces in eligible locations. Yes. If we must free space first, some apparently abandoned pieces may still belong to a reader or a pending upload.
11:46 We need to know what is safe to reclaim. Now return to those abandoned upload pieces. Could a cleanup worker delete pieces past their upload timeout if it can't see them in the current-key list? I'd worry about a race here. For example, a still-pending upload could be about to commit, or a reader could be downloading an older generation after an overwrite. Wait, our current-key list could be perfectly correct and that cleanup could still delete a live version? Yes. We keep durable references, including read leases that record a reader still using the old cut.
12:23 A reader that loses its lease must stop accessing that version. For an expired upload, we first revoke its owner's ability to publish. That's fencing: if that uploader wakes late, its commit is rejected before cleanup removes the pieces. And deletion needs a durable tombstone, a record that the key was removed. Otherwise a late repair job might announce its successfully restored fragment and resurrect the deleted film. Oh no. Then our repair worker would be undoing Nia's deletion. It has to follow the object's lifecycle, even if it rebuilt a perfectly good fragment.
12:56 If she deletes the only retained version, durability can't undo that choice. Version retention is a separate product feature. With cleanup protected, return to the full architecture with Nia's actual upload. The gateway checks her permission. The encoder creates and verifies six fragments in the chosen zones; metadata commits their manifest, and only then she receives success. During the zone outage, the read service pins her committed generation, finds four intact fragments and reconstructs the original bytes.
13:23 The key remains discoverable because metadata survived too. Meanwhile, repair checks each replacement before changing its recorded location. Cleanup keeps the references that active downloads and pending work need. Those restored pieces give Nia's object its margin back. I'd still choose three replicas if our volume didn't justify that machinery. The point of the code is lower stored capacity; the repair and lifecycle work are the price attached to it. Fair. The replica option belongs in our design review too.
13:52 Nia gets the film she stored, and we can explain why the outage was survivable and when it would stop being so. With Nia's film readable, what would convince you it's fully protected? I'd be tempted by the green download dashboard. But four verified fragments only make it readable. Six in our promised placement restore its margin. I'd check how long the other exposed objects are waiting for repair, and whether that queue has eligible capacity. Object storage earns its durability promise before success, then keeps earning it through verification and repair.
14:27 Six stored fragments help only when their placement, identity and metadata remain trustworthy. Thanks for listening to Learning Podcasts.