CodingNodes Space play · ←→ step · R restart

The 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.

Files
~billions
The metadata rows. Small, numerous, and queried constantly — they drive the metadata store's shape.
Bytes
~petabytes
The blob content. Enormous and mostly read-only after upload — they drive the blob store's shape.
Avg file
a few MB
Most uploads are small; a long tail of large files drives the chunking requirement.
Uploads
~10K / s (peak)
Concurrent uploads at peak. Chunked and resumable so none of them blocks on a stall.
List latency
< 5 ms
The metadata path budget. A folder list must feel instant regardless of how big the files in it are.
Blob durability
≥ 3 copies
The bytes are replicated across nodes so the loss of any one node loses nothing.
Chunk
8 MB
The upload unit. Small enough to be resumable, large enough to keep the per-chunk overhead low.

Takeaways

Part 1

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.

  1. 1
    Metadata 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.

  2. 2
    Two 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.

  3. 3
    Why 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.

Part 2

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.

  1. 1
    Cut 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.

  2. 2
    Upload 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.

  3. 3
    Assemble, 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.

Part 3

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.

  1. 1
    Authorize, 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.

  2. 2
    Stream 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.

  3. 3
    Range 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.

Part 4

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.

  1. 1
    An 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.

  2. 2
    Delete 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.

  3. 3
    Why 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.

Part 5

Sharing and permissions

Who may read or write a file is a query the permission service answers on every access. Granting access is writing a rule; enforcing it is checking the rule — and the two are kept separate.

  1. 1
    A permission is a (file, person, role) row

    Sharing a file with someone is storing a rule: this file, this person, this role. The role — viewer or editor — is the only decision made at share time. Everything else, including what 'editor' may do, is defined once and applied everywhere.

  2. 2
    Every access re-checks the rule

    When a person tries to open or edit the file, the Drive API asks the permission service: may this person, with this role, do this? The check happens on the read path and the write path alike, so a permission that was revoked stops working immediately — there is no cached 'yes' to outlive it.

  3. 3
    Folders inherit, files override

    Sharing a folder grants the role to everything inside it, and a file's own explicit permission can override the inherited one. The permission service resolves the effective role by walking from the file up through its folders, which is why a 'private file in a shared folder' is still private.

Part 6

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.

  1. 1
    Content 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.

  2. 2
    Many 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.

  3. 3
    The 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.

★ Finale

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.

  1. 1
    The 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.

  2. 2
    The 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.

  3. 3
    Shared, 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.

  4. 4
    Downloaded, 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

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.

  1. 1
    The 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'.

  2. 2
    Why 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.