Design Google Drive
Ch. 16 Case Studies System designThe problem
A cloud file store looks simple from the outside — a name, a folder, a file — and that simplicity is the hardest part to build. A single file is really two different things living in two different places: a small, frequently-read row of metadata, and a large, mostly-immutable body of bytes. Confusing those two, or storing them together, is the mistake every later problem inherits.
Once the split is made, the design falls out of it. Metadata lives in a fast queryable store; bytes live in a cheap, massively-replicated blob store and are served through a CDN; uploads are chunked and resumable so a flaky connection does not restart a gigabyte; versions and a trash bin make 'delete' recoverable; and a permission service decides, per file, who may read and who may write. We will build each of those, then close the loop with one file going up, being shared, and coming back down through the CDN.
Requirements
Functional — what it must do
- Store: a user uploads a file of any reasonable size and it is durable, addressable by an id, and retrievable later.
- Organize: files live in folders, have a name and a type, and can be searched by the user who owns them.
- Share: a user can grant another person read or edit access to a file or folder, and that access is enforced on every read and write.
Non-functional — how well it must do it
- List a folder or run a search in low single-digit milliseconds — the metadata path must feel instant, independent of file size.
- Downloads of a stored file are served from the edge and support range requests, so a large file streams and a partial fetch does not restart the transfer.
- A file is durable against the loss of any single storage node, and an upload over a poor connection is resumable rather than redone from the start.
Scale — how much it must take
- On the order of billions of files, petabytes of stored bytes, and tens of thousands of concurrent uploads and downloads at peak.
Assumptions — the numbers this design is sized for
A rate limit means nothing without a scale. These are the figures every later part relies on: how much traffic arrives, how much work the limiter has to do per second, and how much latency and memory it may spend doing it.
Takeaways
- A file is two things: small, queryable metadata and large, immutable bytes. Keeping them in separate, job-specific stores is the decision every other piece follows from.
- Chunk uploads into fixed pieces and record per-chunk progress so a stalled transfer resumes from the last good chunk instead of restarting the whole file.
- Authorize the read in the API, then redirect to the CDN; serve bytes from the edge in range requests so large downloads stream and resume without restarting.
- Make 'edit' a new version and 'delete' a move to trash — both are metadata operations over already-stored content, so recoverability costs almost nothing at the moment of the action.
- Model a share as a (file, person, role) rule stored in a permission service, checked on every access, with folder roles inherited and file rules overriding.
- Deduplicate by content hash so identical bytes are stored once and referenced by refcount — the duplicate costs a metadata row, not the file, and the bytes are freed only at refcount zero.
A file is two things
The single most important decision is to separate the small, queryable metadata from the large, immutable bytes. Everything else — the stores, the CDN, the permissions — follows from that split.
- 1Metadata and content, apart
A file is a row of metadata — name, owner, size, created, permissions — and a body of content — the bytes. They have completely different access patterns: the metadata is small, read constantly, and queried by many different keys; the content is large, written once, and read by id. Keeping them in one place would force one shape to serve two masters.
- 2Two stores, two masters
The metadata goes into a fast, queryable database — it must support 'list my files', 'find files named X', 'who can edit this'. The bytes go into a cheap, massively-replicated blob store that only needs to do one thing: hand back the bytes for a given id. Each store is now optimized for exactly one job.
- 3Why the split pays
Because the halves are separate, a folder list touches only the metadata store and is fast no matter how big the files are; a download touches only the blob store and the CDN and is fast no matter how many people share the file. The split is what lets each path be independently cheap.
Chunked, resumable upload
A large upload over a real connection will stall. Chunking the file into fixed pieces and uploading each independently turns a total failure into a resume from the last good chunk.
- 1Cut the file into chunks
The client slices the file into fixed-size chunks — say, eight megabytes each. The upload is now a sequence of independent chunk uploads rather than one long transfer. That reframing is the whole trick: it makes progress measurable and recoverable.
- 2Upload each chunk, record progress
Each chunk is uploaded to the blob store and the server records which chunks have arrived. A 40 MB file is five chunk uploads; when the fourth arrives, the progress is 4 of 5. If the connection drops, the client re-requests and simply resumes from chunk five — the first four are already safe.
- 3Assemble, then record the file
When every chunk is present, the blob store assembles them into the final object and returns its content id. Only then does the Drive API write the metadata row, linking the file's name and owner to that content id. The file 'exists' as a Drive object at the moment the row lands, not when the first chunk did.
Serving bytes from the edge
The download path is the reverse: the metadata store authorizes the read, the bytes are served from the CDN, and range requests let a large file stream without restarting a transfer.
- 1Authorize, then redirect
A download request first hits the Drive API, which checks the file's permissions and, if allowed, redirects the client to a content id on the CDN. The API's job is only authorization and indirection; it never moves the bytes itself.
- 2Stream from the CDN
The client fetches the content id from the CDN. Because the bytes are replicated at the edge, they come from the nearest node, not the origin. A large file streams in range-request chunks, so the transfer can pause and resume — the same resumability the upload had, on the read side.
- 3Range requests make it resumable
Because the client requests ranges — 'bytes 0 to 8 MB', then '8 MB to 16 MB' — a stalled download does not restart from zero. It continues from where it left off, exactly as the upload resumed from its last good chunk. The read path inherits the write path's resilience.
Versions and a trash bin
An edit is a new version, not a destruction of the old one. And a delete is a move to trash, not a free — both make the destructive-looking operations recoverable.
- 1An edit makes a version
When a file is edited, the new content is stored as a new version and the old one is kept, not overwritten. The metadata row points at the current version, but the history remains, so 'revert to yesterday' is a pointer change, not a reconstruction.
- 2Delete is a move to trash
Deleting a file does not free its bytes. The metadata row is moved to a trash state and the content is retained for a retention window — thirty days, typically. Only after that window, or on an explicit empty, is the content actually released. That is what makes a mistaken delete recoverable.
- 3Why both are cheap
Versions and trash are both metadata operations over already-stored content. Keeping a version is holding a row and a content id; moving to trash is flipping a state. The expensive act — deleting bytes — is deferred and rare. Recoverability therefore costs almost nothing at the moment of the action.
Store the bytes once
The same content is uploaded over and over — a popular PDF, a stock image. Storing each copy separately would multiply the bytes for nothing. Deduplication keeps one copy and lets many files point at it.
- 1Content is identified by a hash
When a chunk or a file arrives, the blob store computes a hash of its content. That hash is the content's identity: two files with the same bytes have the same hash, regardless of their names or owners. The hash is what makes 'is this content already here?' a cheap, exact question.
- 2Many files, one copy
Because content is keyed by its hash, the second upload of the same bytes is not stored again — it is a new metadata row pointing at the existing content. The storage cost of the duplicate is the one small metadata row, not the entire file.
- 3The trade: a refcount, not a delete
The cost of deduplication is that a content object can now be referenced by several files, so it cannot be freed while any of them still points at it. The store keeps a reference count per content hash and frees the bytes only when that count reaches zero — the same logic that makes trash retention safe.
End to end
One file's life: uploaded in chunks, assembled, recorded, shared, and downloaded through the CDN — with the metadata and the bytes on separate, independently fast paths the whole way.
- 1The whole system
Every piece in one frame. The client talks to the Drive API; metadata lives in the metadata store, bytes in the blob store, and the CDN sits in front of the bytes for reads. The permission service hangs off the API, checking every access.
- 2The upload, chunk by chunk
A 40 MB file is cut into five 8 MB chunks and uploaded to the blob store, one at a time. When all five are present they are assembled into content H, and the Drive API writes the metadata row pointing at it. The file now exists, durable, with its name and owner recorded.
- 3Shared, and the rule is stored
The owner shares the file with a colleague as a viewer. The Drive API stores that as a (file, person, role) rule with the permission service. Nothing about the bytes changes — only the metadata gains a new row — which is why sharing is fast and per-person.
- 4Downloaded, through the edge
The colleague opens the file. The Drive API checks the stored rule, allows the read, and redirects to the CDN, which serves the bytes from the nearest edge node in resumable ranges. The origin blob store is untouched for a hit — the read path never crossed the metadata path to do its job.
In the wild
The metadata/content split is the backbone of essentially every cloud file and object store. The boxes below are anchored to the classes of well-known systems that run each piece — an illustrative mapping, not a claim about any one product's internals.
- 1The pattern, piece by piece
Each box is a standard building block of a cloud file store. Anchoring them to the classes of production systems that run that piece turns the abstract design into 'the shape behind the file you upload'.
- 2Why the same split keeps winning
Independent file and object stores converge on the same split because each piece removes a real failure: the metadata/content separation removes the two-masters problem, chunking removes the upload-stall failure, the CDN removes origin load, versions and trash remove the destructive-delete failure, and deduplication removes the redundant-byte cost. That convergence is the evidence the design is load-bearing.