Lesson 2 · Minutes 10-20

Object Storage: First Design

Problem

Put the whole store on one machine: that is minutes ten to twenty. A put becomes a file on its disk, and a small table remembers where the file went. This does everything the question asks except keep its word about never, and that exception is how the next ten minutes begin.

Your job here is to take a put, a get and a list down to the disk, grant what this design does well, and hand over the limit in your own words. The quiz is the interviewer's four pushes: say your answer to each one first.

A File per Object and a Key Table

Clients reach one server. It stores each object as a file on its disk, under a path made from the bucket, the key and a unique suffix. A small table on the same machine, the key table, maps bucket and key to that path, the object's size and its checksum. The table is sorted by bucket and key, and that one detail is what makes listing work.

The first design
Clientput, get, delete, list One serverholds everything Key tablesorted, by key Diskone file per object get, list put, delete find path open file first then row readwrite

A Put, a Get, a List

A put writes the whole file and flushes it to disk. Then it adds the row, flushes that, and only then answers. The order matters: data first, row second. A crash between the two leaves a file no row refers to, which wastes some space, and never a key pointing at nothing.

A put that replaces a key does the same with a new file. Updating the row is the moment the new object takes over, so a reader gets the old object or the new one, and then the old file goes.

A get reads the row, opens the file at that path, and streams it, checking the bytes against the checksum. No row means not found. A list is a range scan on the sorted table, from the first key with the prefix to the last, so it returns keys in order without opening a single file.

A delete removes the row, then the file. The key stops resolving as soon as the row is gone, and a crash before the second step leaves one more file that nothing refers to. A client that lost its answer repeats the call: a second put stores the same bytes again, and a second delete finds no row and answers the same. Those stray files wait for a sweep, which arrives with the first probe.

What One Server Gets Right

Put, get, delete and list by prefix all work, for any object that fits on the disk. A read straight after a put sees it, because there is only one place to look. Picture one team with 10 terabytes on a 20-terabyte disk, a backup, and tolerance for a bad day. This is all the object store that team needs, and the interviewer hears that from you before any limit comes up.

Four Limits, Left Alone

One disk holds every object, at about 1.5 percent a year, and no byte has a second copy. A billion small objects means a billion files. A very large upload is one long request. And the table sits on the machine that holds the bytes. All four stay on the board untouched until someone pushes.

The first one you give away before anyone asks: "One disk's failure has to be acceptable for this to stand, and at about one and a half percent a year it's a matter of time. The day it fails, every object is gone, which is the opposite of the question. So: copies."

Interview Pitfalls
  • Skipping the one-server design because the question says cloud. The interviewer never hears why each later box is there.
  • Starting from a quorum. Objects do not change and the table says where they are, so there is no version to vote on.
  • Writing the row before the bytes are on disk, so a crash leaves a key that points at nothing.
  • Leaving out listing because it looks easy. It comes back as the reason the metadata is sorted.
What Interviewers Listen For
  • A put, a get and a list each traced down to the disk.
  • The order of a put stated without a hint: data, then the row that points at it.
  • About 1.5 percent a year set against the question's never, before the interviewer asks.

Knowledge Check

"The disk holding your objects just failed. What did you lose, and what would you change?"

  • "Back up the disk each night, and restore all the objects from it after a failure."
  • "Write three copies on three racks, and move the key table off the storage nodes."
  • "Mirror the disk inside that server, so that one failed drive will never lose data."
  • "Buy more reliable drives, and swap each one out well before it reaches rated life."

"Three copies means paying for three times the data. Can you keep the durability and cut that?"

  • "Drop to two copies, and add a checksum so that a bad copy is always detected."
  • "Compress each object before storing it, and keep all three copies of the result."
  • "Keep one copy on fast disks, and move the other two to a cheaper offline tier."
  • "Cut each object into ten pieces plus four parity, so any ten rebuild the rest."

"A customer stores a billion 10 KB objects, and your design turns that into a billion files. What breaks?"

  • "Append small objects into large containers, and keep each offset in a metadata row."
  • "Nothing does, because it is only 10 TB of data, which easily fits on one disk."
  • "Raise the file system's limit on files, and add memory to hold all of its inodes."
  • "Store small objects directly in the metadata rows, right alongside their keys."

"Now someone uploads a 5 TB object over one connection. How does that go?"

  • "Raise the request timeout to several hours, and have the client retry on failure."
  • "Stream it through a front-end server, which cuts it into parts as the bytes arrive."
  • "Upload numbered parts independently and in parallel, then publish them all in one commit."
  • "Have the client split it into smaller objects, and leave the joining to the reader."

You got correct