Users expect every file on every device, always, and never a lost edit. Splitting files into blocks named by their content makes uploads small, storage deduplicated, and sync a matter of comparing lists of hashes.
Requirements. Upload and download files of any size, sync them across devices, keep version history and share files and folders; never lose a file, send as few bytes as possible, keep metadata strongly consistent, at hundreds of petabytes.
Commits
5,800 per second500M file changes a day
Storage
500 PB100M users × 5 GB, before deduplication
Block size
about 4 MBa typical edit uploads one block
The design. Files are split into blocks of about 4 MB named by their SHA-256 hash, so a client uploads only the blocks the server lacks and identical blocks are stored once. A commit lists the new version’s block hashes and the version it was edited from, and the metadata database accepts it only if that version is still the latest; otherwise the client saves a conflicted copy. Each folder has an ordered journal on one shard, and every device long polls it with a cursor to pull the changes it has not seen.
Interview prompt
Design Dropbox or Google Drive: files placed in a folder appear on all of a user’s devices and can be shared with others.
Requirements and estimates
Functional requirements
Upload and download files of any size.
Automatic sync across devices.
Version history and restore.
Share files and folders.
Non-functional requirements
Durability above all: never lose a file.
Sync quickly while sending as few bytes as possible.
Metadata is strongly consistent.
Hundreds of petabytes.
Estimates
Commits 500M file changes per day ≈ 5,800 commits/sStorage 100M users × 5 GB = 500 PB before deduplication
Upload a typical edit changes one 4 MB block, not the whole file
API and data model
API
POST /v1/blocks/check { hashes: [...] }
→ which hashes the server is missing
PUT /v1/blocks/{hash} one 4 MB block
POST /v1/files/commit
{ path, baseVersion, blockHashes: [...] }
GET /v1/changes?cursor=c_9812 long poll
What you sketch in the first five minutes, before any of the detail below. Draw the blocks, then the race between two devices.
1. Blocks named by their hash
Say: never move a whole file when one part changed, and never store the same bytes twice.
Split each file into blocks of about 4 MB and name each by its SHA-256 hash.
Ask the server which hashes it already has.
Upload only the missing blocks to object storage.
Next question: insert one byte at the start and every fixed block shifts. Content defined chunking moves the boundaries with the content, so only one or two blocks change.
2. The commit check
Say: a block never changes once written, so all the hard consistency lives in the metadata.
Commit the new block list with the version it was edited from, its base.
Accept only if the base is still the latest: append to the journal and bump the version in one transaction.
Rejected? Save the edit as a conflicted copy, never overwrite.
Next question: why one shard per folder? So the folder's journal has one strict order that every device can follow with a cursor.
File chunking and block deduplication
Split each file into blocks of about 4 MB and name every block by its SHA-256 hash. Before uploading, the client asks which hashes the server already has and sends only the missing ones. The same block stored by a million users is kept once. Fixed size blocks have one weakness: inserting a byte near the start shifts every boundary. Content defined chunking places boundaries with a rolling hash, so they move with the content and an insert changes only one or two blocks.
The commit protocol and sync conflicts
Upload missing blocks to object storage.
Commit the new version with its block list and the baseVersion it was edited from.
The server accepts only if baseVersion is still the latest, appends to the folder’s journal and bumps latest_version, all in one transaction.
If another device committed first, the commit is rejected and the client saves its edit as a conflicted copy instead of overwriting.
Metadata lives in a relational database sharded by namespace (a user’s root or a shared folder), so each folder’s journal is on one shard and strictly ordered. Devices remember their position in the journal as a cursor and long poll for anything newer.
What the interviewer probes next
A 2 GB upload fails at 80%.
Blocks already uploaded stay on the server. The client asks again which hashes are missing and resumes from there.
How do deletes free up space?
Deletes are soft and kept in version history for a period. A garbage collector removes blocks whose reference count has reached zero.
A shared folder has 10,000 members.
The folder is its own namespace with one journal. Members’ devices follow that journal, and change notifications fan out through pub/sub.
Why not store files in the database?
Large blobs bloat the database and its backups. Object storage is far cheaper per byte and built for durability; Amazon S3 is designed for eleven nines.