Lesson 3 · Minutes 20-30

Object Storage: Scaling It

Problem

At minute twenty the interviewer starts with the disk you volunteered, and over the next ten minutes the bill grows before it shrinks. First that disk dies, and you say what was lost and what you change. Then your answer comes back as a bill for three times the bytes, with a request to keep the safety and cut the cost. Then one customer's tiny objects turn your disks into a billion files. Last, a single upload of five terabytes has to cross one connection.

The Failed Disk

"Say that disk dies this afternoon. What's gone, and what do you build so that it isn't?" On this design, everything is gone. So each object gets three copies on three racks, chosen so that they share no failure domain below the zone, the idea in Chapter 6's Regions and the Arithmetic of Nines.

Two more things move in the same step. The server becomes a tier of stateless front-ends behind a load balancer, so losing one costs only the requests it had open. And the key table leaves the machines that hold bytes. It becomes a metadata service: a consensus group replicating the table, as in Chapter 5's Leader Election and Consensus, where a majority must accept each change and the members elect a new leader when theirs goes silent.

A put now writes all three copies, then commits the row, then answers. Data first and row second, as before, so a crash leaves bytes nothing refers to and never a key pointing at nothing. A background sweep removes those leftovers once they are old enough that no put could still be writing them. A copy that cannot be written goes to another rack instead.

A get carries the same promise from the other side. It reads the row from the group's leader, so it sees the last confirmed put. Then it takes any of the three copies and checks the bytes against the checksum. A copy that is silent or fails the check is skipped for the next one, and reported. While the group elects a new leader, puts and gets both wait, and that counts against the 4.4 minutes, not against durability.

Data nodes report to the metadata service, and a repair worker watches those reports. When a disk goes quiet, the worker finds the objects short of a copy, reads a surviving one, and writes a new copy on another rack. A 20-terabyte disk at about 250 megabytes a second is 80,000 seconds, about a day to rebuild. At ten failures a week, the repair worker never stops.

What it costs: three times the bytes, 660 petabytes; a network hop on every put; and a repair stream to throttle, so that it does not take the disks away from reads. Then park the bigger question out loud: "Three copies for now. I'll come back to whether the durability sum really clears the target."

The Tripled Bill

"You're paying for 660 petabytes to keep 220. Get me the same safety for less." The change is erasure coding. Cut the data into ten pieces, compute four parity pieces from them, and put the fourteen on fourteen racks. Any ten rebuild the rest, so any four can be lost. One such set of fourteen is called a stripe.

Fourteen over ten is 1.4 times the bytes, about 310 petabytes against 660. At 20 terabytes, that is about 15,000 disks against 33,000, and about four failures a week against ten. Reads stay cheap, since the ten data pieces hold the bytes as they are, so a normal read touches only the pieces it needs.

Three copies against ten plus four, on 220 PB
Three copies3 times the bytes
660 PB on 33,000 disks. About ten failures a week. A repair reads 20 TB to rebuild 20 TB.
Ten plus four1.4 times the bytes
About 310 PB on about 15,000 disks. About four failures a week. A repair reads 200 TB to rebuild 20 TB.

What it costs shows up in repair. Rebuilding one lost piece reads ten, so a 20-terabyte disk's repair reads 200 terabytes across racks. Four disks a week is 800 terabytes, against 200 for three copies. Over about 700,000 seconds in a week, that is about 1.1 gigabytes a second, about a tenth of one 100-gigabit link. So it is affordable, and it has to be throttled.

Two more costs follow. A read that wants a missing piece has to gather ten disks instead of one. And a 10-kilobyte object cut into fourteen is fourteen tiny writes, which is exactly where the next push lands.

A Billion Small Objects

"One customer has a billion 10-kilobyte objects. How do your disks and your table like that?" Two things break, and each gets a change. The file system goes first. Assume three seeks to open a file whose entry is not in memory. That is 18 milliseconds against 6, about 55 file reads a second on a drive that can do 170. That matters once disks hold small objects. On 15,000 disks, the peak's 100,000 reads are under 7 a second each at a mean of 200 kilobytes. A disk of 10-kilobyte objects holds twenty times as many, so up to about 130 a second, which three seeks cannot serve and one seek can. Coding makes it worse, because a 10-kilobyte object becomes 1-kilobyte fragments on fourteen disks.

So objects are appended to large open containers, assume 1 gigabyte each, with three copies while open. The row now holds a container and an offset, so a read is one seek. A billion of these objects is 10 terabytes, about 10,000 containers, and the file system tracks those instead of a billion files.

A container is sealed when it is full, or after an assumed hour so that a quiet one does not sit in three copies forever. Sealed means it takes no more bytes, and only then does a background worker code it as one unit. Parity over a container still growing would have to be recomputed on every append. Once sealed, 1 gigabyte gives ten pieces of 100 megabytes, and the worker removes the three copies when all fourteen are safe.

Each open container has one writer, a front-end holding a lease on it, so all three copies keep the same bytes at the same offsets. If that front-end dies, its lease runs out. The sealing worker tells the copies to refuse more bytes, then seals at the shortest length among those that answer. That still holds everything any row points at, since a row is written only after all three copies have its bytes. A front-end that was only paused finds its copies refusing, and its put fails. A copy that fails partway ends its container early in the same way.

One small table closes a hole here. If every row named its disks, sealing or repairing a container would rewrite thousands of rows. So a row names only a container and an offset, and a placement table in the metadata service says which disks hold each container. Sealing and repair change one line of it, and no object's row. With every byte in 1-gigabyte units, assume 500 bytes a line: 220 million lines is 110 gigabytes, and one group holds that. Front-ends cache the lines, since a stale one fails at the disk and they simply ask again.

An object's life
Appendedopen container
→
Sealedno more bytes
→
Codedfourteen pieces
→
Compactedholes removed

The table is the second thing, and here the customer's billion is only the way in. A billion rows is 500 gigabytes, a quarter of one node, so one group holds this customer easily. But the table holds every customer, and a billion is one day of what Scope agreed. Three years of days is 1.1 trillion rows and 550 terabytes, which do not fit one group.

So the metadata splits, by range over bucket and key, which keeps each page of a listing one short scan, as in Chapter 3's Range, Hash and Directory. At 2 terabytes a node, that is at least 275 partitions, each its own consensus group.

A small map of the ranges, in a group of its own, says which partition owns which keys. Front-ends cache it, so they keep working through a short outage of that group. A partition refuses a key it no longer owns, and the front-end reads the map again.

What it costs: a deleted or replaced object is a hole in its container, dead bytes that stay until compaction rewrites the container. Call them the holes, and leave them for the deep dive by that name. A container is also a larger unit to lose. And a range split moves load around as prefixes grow hot.

The Five-Terabyte Upload

"Five terabytes over one connection, and it drops in the last minute. Now what?" At 10 gigabits a second, about 1.25 gigabytes a second, 5 terabytes takes about 67 minutes as one request, and any failure starts it over. The change is multipart upload, the move Chapter 19 made from the client's side when a phone connection dropped. This is the store's side: what it keeps for a session, where a part goes, and what makes the last call atomic.

The client opens a session, sends numbered parts in any order and in parallel, then calls complete. Assume 1 gigabyte a part. That is 5,000 parts, within the limit of 10,000, each under a second on the same link. The agreed 50 terabytes takes the largest part a major store allows, 5 GB, and all 10,000 of them. One link still needs its 67 minutes, but a failure now costs one part.

The upload calls
POST /{bucket}/{key}?uploads                 200 {"upload": "u7"}
PUT  /{bucket}/{key}?upload=u7&part=1        200 {"checksum": "9f2c..."}
POST /{bucket}/{key}?upload=u7               {"parts": [1, 2, ...]}
                                             200 once published

Those are three calls: one opens the session and returns its ID, one sends a numbered part and returns that part's checksum, and one closes the session with the list of parts it should hold. A list naming a part the session lacks is refused.

The session is one row in the metadata service, in the partition that owns the key. Each part that lands adds a small row of its own beside it, with its number, size, checksum and location. A part this size skips the containers and gets its own coded stripe, as does anything over an assumed 100 megabytes, since it is already large enough to code alone. Each stripe gets its own line in the placement table, so repair never touches the list, and even if every stripe stopped at 100 megabytes, the table is about a terabyte, still one group. A part sent twice replaces the earlier one, whose bytes go to the sweep.

Complete is what makes it atomic. The front-end first stores the part list as an object of its own, since at an assumed 100 bytes a part it is 500 kilobytes, a thousand times what a row was sized for. Then one conditional write, which applies only if the session is still open, publishes the row that points at the list, the kind of write in Chapter 5's Leases, Locks and Fencing. Until that write, readers get whatever the key held before. A repeated complete finds the session closed and returns the same answer.

You can hold all of it in one line: "The part is the unit of failure and the commit is the unit of visibility." A get then reads the row, the list, and the stripes it needs.

What it costs: a session to keep, parts from abandoned uploads that are paid for until they expire, and a checksum that no longer covers the object as one piece, so each part carries its own. Assume a session expires after seven days without a new part. A sweep then closes the row, so a late complete is refused, and only then deletes its stripes.

The Full Design

Clients reach a load balancer, then stateless front-end servers. The metadata service holds at least 275 range partitions, each a consensus group, along with the placement table and the map of ranges. Data nodes hold open containers with three copies, sealed containers in fourteen pieces across racks, and the stripes of large objects. Background workers run repair, sealing and the sweep.

A small put appends to an open container, then commits its row. A large one sends parts to stripes and commits once. A get reads the row, then one copy or the pieces it needs. The figure marks what is new.

The full design, changes marked new
Clientput, get, delete, list Load balancerany serverNEW Front-endsstateless servers Metadata service275 ranges, consensusNEW Open containersdata nodes, 3 copiesNEW Sealed, codeddata nodes, 14 piecesNEW Workersrepair, sealing, sweepNEW get, list put, parts find row read append parts row or commit when full code, repair readwriteasyncNEWsince the first design
Interview Pitfalls
  • Coding each small object on its own. The interviewer asks what a 10-kilobyte object becomes on fourteen disks.
  • Hashing the keys for the metadata, then being asked to list by prefix. A list now visits all 275 partitions.
  • Answering the bill with two copies. One failure leaves one copy, and ten failures a week make that normal.
  • Treating repair as free. Rebuilding reads ten pieces for each one lost, and the interviewer wants that in bytes.
What Interviewers Listen For
  • Copies and coding priced in disks, and repair priced in bytes.
  • The order of a put stated, data then row, and what a crash between the two leaves behind.
  • When an object is coded, said without a hint: sealed containers only, and why not sooner.

Knowledge Check

Under ten plus four, a 20 TB disk fails. What does its repair read across racks?

  • About 20 TB, the same amount that the failed disk was holding
  • About 200 TB, ten pieces read for each one that is rebuilt
  • About 28 TB, since the code stores 1.4 times the original bytes
  • About 280 TB, all fourteen pieces read for each one that is lost

Why is a container erasure-coded only once it is sealed?

  • Three copies survive more failures, so coding it early loses safety
  • A reader cannot find an object until its container has been coded
  • Its bytes have stopped changing, so the parity is computed once
  • Sealing is the step that writes each object's row to the metadata

A customer deletes a 10 KB object held in a sealed container. What happens to those 10 KB?

  • They are zeroed on all fourteen pieces as a step of the delete
  • They are reused for the next 10 KB object that gets appended
  • They go the next time the repair worker rebuilds that container
  • They stay as dead bytes until compaction rewrites the container

What does the complete call of a multipart upload guarantee?

  • Readers see the whole object or nothing, once the list is published
  • Every part has arrived in order, over one unbroken connection
  • Every part has been appended to an open container, with copies
  • The parts have been joined into one file before the call answers

You got correct