CHAPTER DEEP READ · System Design Interview Vol 2 · Ch 9

Design an S3-like Object Storage

System Design Interview Vol 2 · Ch 9 · Alex Xu & Sahn Lam · 2022

中文 →

What is this chapter about?

The photos your phone backs up, the images and videos on every website, the logs your company is never allowed to delete — most of them live in something called object storage. This chapter builds one from scratch: how to make it hold everything, never lose anything, and still be cheap.

One strange rule

This kind of warehouse has a rule that sounds ridiculous: once something is stored, you may not edit it in place. Want to change one character? Store the whole thing again.

And yet that single concession buys everything else. Because nothing ever changes, you never have to worry about whether the copies agree with each other. Because you never have to worry, you can freely keep extra copies, put them far away, and put them on very cheap disks. It isn't stuck this way — it deliberately gave up one ability to buy a pile of others.

Why the old way struggled

The familiar way to store things is nested folders, like on your laptop. Fine for a few thousand items; hopeless for a few billion, because the directory itself gives out first — the ledger of "what is this called and where does it live" grows too big for any one machine.

Small items are worse. The warehouse staples a registration card to every single item. A photo may be only tens of kilobytes, but its card costs the same as any other. A few billion cards weigh more than the goods.

The core ideas, in plain terms

① Split the ledger from the shelves. "What is it called, whose is it, when did it arrive" goes into a ledger; the bytes themselves get piled on shelves. A claim ticket links the two. The ledger is edited constantly, so it uses a system good at edits; the shelves are append-only, so they use the cheapest disks going.

② Bundle the small stuff. Don't give every tiny photo its own box. Stack hundreds of them into the same big crate and note in the ledger: "crate 7, this far in, this long." To fetch one, reach straight to that stretch — no need to unpack the crate.

③ Three copies, or shards plus spare cards. The clumsy way to survive loss is three identical copies, costing three times the space. The clever way: split one item into 8 pieces, then compute 4 extra spare cards from those 8. Put all 12 on different machines. Lose any 4 and the rest still reconstruct the original — like knowing a recipe well enough to work out a missing ingredient. It costs only half again as much space, yet survives more.

④ Regular checkups. Bytes on a disk quietly rot, with nothing reporting an error. So record a "fingerprint" on the way in, have a background job re-check it periodically, and silently repair from a good copy whenever it fails to match.

What it costs

Shards save space, but fetching means gathering several pieces and reassembling them, so it is slower than grabbing one ready-made copy — which is why popular items usually still get plain duplicates.

One line to remember

Object storage is a deliberate subtraction: give up editing in place, and you get near-infinite scale, cheap disks and extraordinary safety. You do it by splitting the ledger from the shelves, bundling small items so their registration cards stop dominating, replacing three full copies with "shards plus spare cards" at one-and-a-half times the space, and running checkups so bytes can't rot unnoticed. The cost: fetching means reassembling, so it's a little slower.

Want the mechanisms, the notation and the diagrams? → Switch to the deep read