Lesson 4 · Minutes 30-45

Object Storage: Deep Dives and Curveballs

Problem

Nobody has yet checked the design against the target from Scope, and at minute thirty you do that yourself. The last fifteen minutes open on the durability sum you parked. After it come the reason the metadata lives apart from the bytes, then the holes, then four curveballs.

The Durability Sum

Start with one disk. About 1.5 percent a year over 365 days is about one chance in 25,000 that a given disk dies on a given day. A day is the window that matters, because a day is the rebuild time.

Three copies first. Once one disk goes, the object is lost if the other two go that same day, and that is one in 625 million. An object sits on three disks at 1.5 percent each, so the first failure comes at 4.5 percent a year. Together, that is about one chance in 14 billion a year, near ten nines. Across 1.1 trillion objects, it is about 80 lost a year, which misses the target.

Now fourteen pieces. Once one disk goes, the object is lost only if four of the other thirteen go that same day. There are 715 ways to pick those four, and each is one in 25,000 to the fourth power. The first failure comes at 21 percent a year, because there are fourteen disks. That works out at about 15 nines, one object in over two thousand years across the store. So the cheaper scheme is also the safer one.

The sum for one object
Three copies3 disks, one day to rebuild
First failure: 4.5% a year. Two more that day: 1 in 625 million. About 1 in 14 billion a year, near ten nines. About 80 objects a year across 1.1 trillion.
Fourteen pieces14 disks, one day to rebuild
First failure: 21% a year. Four of thirteen that day: 715 ways at 1 in 25,000 to the fourth. About 15 nines. One object in over 2,000 years across the sealed stripes.

That figure is for sealed stripes. Up to an hour of puts, 36 million objects, sits on three copies, about one object in 400 years, and that still clears the target. And the day is the lever: two days is sixteen times the risk, so repair's throttle has a floor. Packing small objects leaves that average alone and changes its shape. A lost container takes thousands of objects with it, so losses are rarer and larger. The sum also counts only whole disks. A sector that goes bad quietly is found only when something reads it. So each data node also reads its own disks on a slow cycle, checks every piece against a checksum stored with it, and reports a bad one to the repair worker. A full pass is about a day of one disk's time, so an assumed monthly cycle takes about a thirtieth of it.

The sum so far counts bytes, and an object is just as lost without its row. Rows sit on three copies, the scheme this sum has just failed. A 2-terabyte node rebuilds in about two hours, not a day. Assume metadata nodes fail at the disk rate. The same sum then gives about half a row a year on average. That is under the target only by a factor of two, on an assumed failure rate, and when it happens it is a lump of 4 billion rows at once. So rows and placement lines get five copies: 1,375 nodes against 825, small beside 15,000 disks.

All of it assumes independent failures, and that is the part to attack. A rack, a bad firmware batch and a deploy each take out many disks at once, and the sum knows nothing about them. Failure domains are the design, and the sum only justifies them. When the interviewer asks how sure you are, say so: "Fifteen nines is true only if failures are independent, and they aren't. So I'd spend my time on what the fourteen pieces share."

Failure domains: what one failure takes out of fourteen pieces
Disk
One piece of fourteen. Routine, about four a week.
Host
One piece of fourteen, since no two pieces share a host.
Rack
One piece of fourteen, since each piece has a rack of its own.
Zone
Five of fourteen across three zones, one more than the parity covers.
Region
All fourteen. Cross-region replication was ruled out in Scope.

Walk up the domains and the code holds until the zone. Across three zones, fourteen pieces put five in one zone, one more than the parity covers. Those objects are out of reach until the zone returns, and gone if it never does. A store that must survive a zone needs no more pieces in a zone than it has parity. Eight plus four just holds, four a zone, but while that zone is out one more failed disk puts objects out of reach. Nine pieces plus six, five a zone, keeps one piece spare. That is 1.67 times the bytes, about 370 petabytes and 18,000 disks.

So the choice turns on what a zone's loss may do. Ten plus four holds while a lost zone may be an outage that ends, and a short one: under 99.99 percent, an hour of it spends the year's 53 minutes. The first customer who needs that loss to be invisible moves the store to nine plus six, about 20 percent more disks, and that is a question for the interviewer now.

Metadata Apart From the Bytes

The store is two systems for one reason. The bytes never change and can be checked against their checksum, so they need no agreement, and no quorum is drawn for them. Chapter 4's Quorums makes a read meet the latest write when copies can disagree. Copies of these bytes cannot disagree, and the row says where they are, so there is nothing to vote on.

Only the row changes, so the promise lives there: a linearizable conditional write per key, in the terms of Chapter 4's Consistency Models That Come Up. It is one operation on one partition's consensus group, a round trip of 1 to 2 milliseconds across zones, so a few milliseconds a write.

Range partitioning keeps a list a scan, at the cost of hot ranges. Keys that begin with a date all land at one end, and splitting handles the load after the fact. A key that only ever grows at one end keeps its last partition hot however often it splits, so writers there are told to slow down.

A hash partition has no hot end and no cheap list. So the trigger for hashing is a store that never lists, and here the list agreed in Scope settles it.

The Holes

Back to the holes you parked. A deleted or replaced object leaves its bytes in a sealed container, and they cannot be cut out, because the parity covers them. A compaction worker picks containers past an assumed quarter of dead bytes, copies out what is alive, seals and codes a new container, updates every row that moved, and retires the old one.

To find those containers, the worker walks a copy of the key table on a slow cycle and totals the live bytes each container still has. It judges only containers sealed before that copy was taken, since a newer one would look empty. It never counts a delete down, so a repeated delete changes nothing.

Each row moves by a conditional write that checks the old location, so a concurrent delete wins, and the copied bytes simply become dead in the new container. A crash halfway leaves the remaining rows on the old container, which is still whole, and the worker carries on from there. The old container goes only through the sweep: a week later, and only if a walk begun after the last move finds no row pointing at it, so a reader who already holds the old location still finds its bytes.

Compaction writes bytes no user asked for, moves thousands of rows per container, and competes with repair and reads for the same disks. So it runs under a budget. A low threshold compacts too often, and a high one pays for dead bytes longer. Very large objects skip all of this, because their stripes are dropped whole.

Three Copies vs Erasure Coding

Three copies cost 3 times the bytes and survive two failures. A read is one disk, and a repair reads as much as it writes. Use them for what is being written and may be read at once: the open container.

Erasure coding, at ten pieces plus four, costs 1.4 times and survives four failures. A repair reads ten pieces for each one, and a degraded read, one that wants a missing piece, has to gather them. Use it for anything sealed, which here is nearly all the bytes.

Curveballs

"Add versioning." The key table's key gains a version, newest first, and a get reads the first row. A put replaces nothing, and a delete writes a marker. Nothing changes on the data nodes, which is the argument for having kept them apart. What it costs: rows and bytes grow with every overwrite, so it comes with an expiry rule, and listing has to skip the old versions.

"Read-after-write on every request, including lists and through any cache." The row is already linearizable, so a get after a put is covered. Now find every other place that holds a copy of the answer. A front-end that caches rows has to validate each one with a version check, so it saves bytes and not the trip. A separate listing index updated later would break the promise, and the sorted key table has none. The cost is the trip to the partition's leader on each request, kept to one row per operation.

"A rack loses power." Nothing is lost: one of fourteen pieces per stripe is out of reach, and the rest serve every read, more slowly. So do not start repairing yet. Assume 40 disks a rack. That is 800 terabytes, and at ten pieces read for each one, 8 petabytes of repair traffic. That is about a week of one 100-gigabit link running flat out, for a rack that may be back in an hour.

The strong move is a timer. The repair worker sees 40 disks go quiet together and waits, assume two hours. Then it repairs in order of risk, stripes with the fewest pieces left first, which the placement table can list. What the timer costs is a window with less margin: for those hours, the rack's stripes survive three more failures, not four.

"Deleted data must really go." A delete has three clocks. The row goes at once, so the key stops resolving. The bytes stay until compaction, and a container that never passes a quarter dead can hold them indefinitely, so compaction promises no date. And a sweep finds bytes no row, part list or open session refers to. Its grace period, assume a week, is counted back from the start of its walk, because a put in flight has written bytes and not yet its row.

Where a deadline is legal, give each object its own encryption key, kept in the row, wrapped under a master key the key service holds, and destroy the key: the bytes are unreadable at once, on every disk. The cost is a key per object and a key service on the put and get paths, whose downtime counts against the 4.4 minutes. Any snapshot of the key table would keep a destroyed key alive, so the deadline also limits how long a snapshot lives.

How Each Level Answers

A mid-level answer gets to copies and separate metadata once the disk fails, and knows erasure coding exists and is cheaper. It works 1.4 against 3 when prompted, and comes to small objects when the interviewer raises the billion files. It says durable as a word until asked for the number.

A senior answer turns never lose into a number in Scope, and prices each change in disks. It states the order of a put and when a container is coded. It reaches range partitioning from listing, raises compaction as the cost of packing without being asked, and works the durability sum far enough to say which scheme clears the target.

A staff answer drives the durability sum to the point where it stops being true, and attacks the independence assumption, proposing failure domains as the real design. It finds that fourteen pieces cannot survive a zone and prices the code with a piece to spare. It asks what customers will pay per byte, because the answer sets the code, and holds the delete deadline and the repair budget as commitments to keep while running.

Interview Pitfalls
  • Reciting the algebra of the code. The interviewer wanted what a repair reads, in bytes, and that is one sum.
  • Repairing at once when a rack goes dark, and turning a power cut into 8 petabytes of cross-rack traffic.
  • Answering really delete with delete the row, while the bytes sit in a container and the repair queue.
What Interviewers Listen For
  • The durability sum done in steps a listener can follow, then a statement of where it stops being true.
  • The failure domain that defeats the chosen code, named without a hint.
  • The rack waited out, for a stated time, with the order of repair after that.

Knowledge Check

A rack of 40 disks goes dark, and nobody knows why yet. What is the best move?

  • Start rebuilding all 800 TB now, while the thirteen pieces remain
  • Wait out a stated timer, then repair stripes with the fewest pieces first
  • Stop serving reads from those stripes until the rack comes back
  • Raise each stripe on that rack to three full copies until the rack is back

Adding versioning changes the key table. Why do the data nodes not change at all?

  • Each version becomes a new bucket, which the nodes already know how to handle
  • Old versions are removed before their bytes reach any data node
  • They hold immutable bytes, and only rows say what a key currently means
  • Data nodes already track every version of each object they store

Lists must show a confirmed put at once, through any cache. What does that need?

  • A separate listing index, updated by a queue just after each put
  • A longer expiry on front-end caches, so they stay warm for lists
  • A quorum of data nodes, each one asked which keys it happens to hold
  • A scan of the sorted key table itself, with no index updated later

A delete must make the bytes unreadable today, and compaction runs next month. What does that?

  • Destroying a per-object encryption key that was kept in the row
  • Deleting the row, since then no key in the store resolves to those bytes
  • Running the sweep, which finds bytes that no row refers to
  • Lowering the compaction threshold, so every hole is rewritten

You got correct