Books Deep-Read · System Design Interview Vol 1 · Ch 15

Design Google Drive

System Design Interview Vol 1 · Ch 15 · Alex Xu · 2020

中文 →

What is this chapter about?

You edit a file on your laptop, open your phone, and the new version is already there. This chapter asks: what do you have to build to do that for tens of millions of people? The answer is slightly counter-intuitive — storing the file turns out to be the easy half. The hard half is keeping five devices telling the same story about which version counts right now.

A strange fact first

You change one word in a two-hundred-page document, and the service does not re-send those two hundred pages. It sends only the small piece your edit landed in. As far as it is concerned, your file was cut into a stack of small cards long ago; you touched one card, so it replaces that card.

Why the old world was hard

The old way was to re-upload the whole file. Nobody minded while files were small. But once you edit a few-hundred-megabyte design file every day, on a phone hotspot, the cost turns absurd: change one word, wait half an hour. Worse, your devices are never online at the same time — the laptop is shut the moment you finish, the tablet wakes three days later, and both may have been edited in between. The system has to untangle that for you.

The mechanism: three intuitions

① Cut the file into small cards. Before uploading, split it into roughly equal pieces; compress, encrypt and store each one on its own. Later, an edit only replaces the card it touched.

② Keep the goods and the ledger apart. A file-sync service is really two systems: one holds the goods (those pieces), the other keeps the ledger (who owns which file, which version, which pieces it is made of). Everything you actually see — folders, names, version history — lives in the ledger. The goods half was solved by cloud warehouses years ago; almost every remaining hard problem is in the ledger.

③ Whoever reaches the ledger first wins. Two devices edit offline and come back online together. The ledger accepts whichever arrived first; the later one is not quietly overwritten but saved beside it as a "conflicted copy", left in front of you to decide.

How to choose

Every trade-off collapses into one question: how big should a card be? Too small and the ledger's line count explodes until bookkeeping alone sinks the system. Too big and changing one word means re-sending a lump again. The industry's answer lands at a few megabytes — big enough that the ledger can keep up, small enough that a re-send does not hurt.

The cost is honest: you save bandwidth and pay in ledger. Once someone has a lot of files, the slow part is usually not the transfer — it is working out which pieces need sending at all.

Remember this one line

A cloud drive is not a storage system, it is a sync system. The file is chopped into pieces and handed to a cloud warehouse; the real craft is in the ledger that records who has what, at which version, assembled from which pieces. And when two sides disagree, it chooses to show you the conflict rather than decide for you.

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