Save a file on your laptop and it's on your phone a few seconds later. “Design Google Drive” or “design Dropbox” is a frequently reported question at Google, Microsoft and Amazon. The magic is not storage, which is cheap; it's syncing efficiently and safely: never re-uploading what hasn't changed, and never losing an edit when two devices disagree.
Step 1 · Requirements
- Functional: upload and download files; automatic sync across devices; folders; file history (versions); share files and folders with permissions.
- Non-functional: never lose data (durability); sync quickly; efficient on bandwidth and storage; works offline and catches up later; large files (several GB).
- Out of scope (say it): real-time co-editing like Google Docs (a different problem), full-text search, previews.
Step 2 · Estimates
- Users: 50 million users × 10 GB average = 500 PB before deduplication and replication. Storage cost dominates.
- Activity: 10 million daily active users × 20 file changes = 200 million commits a day ≈ 2,300/s.
- Reads vs writes: roughly balanced, but block downloads are big and should be served from object storage or a CDN, not app servers.
Step 3 · API
POST /blocks/check { hashes: ["a3f…", "new1…"] } → { missing: ["new1…"] }
PUT /blocks/{hash} (4 MB of bytes, via a pre-signed URL) → stored in object storage
POST /files/commit { path, baseVersion: 7, blocks: ["a3f…", "new1…", ...] }
→ { version: 8 } or 409 Conflict
GET /changes?cursor=c_5512 → files changed since my last syncStep 4 · Design
🎮 Edit a 40 MB file, then sync
Report.docx · 40 MB · split into 10 blocks of 4 MB (click to edit)
Click blocks to “edit” them, then sync. Uploading only changed blocks is why a small edit to a big file syncs in a second. Turn on the conflict to see why Dropbox creates “conflicted copy” files.
The data model
files (file_id, owner_id, parent_folder_id, name, latest_version, is_deleted) versions (file_id, version, block_hashes[], size, created_at, device_id) blocks (hash PK, size, storage_location, ref_count) -- shared across files and users shares (file_or_folder_id, user_id, role) -- viewer / commenter / editor
Metadata needs transactions (a commit must update the file and add a version atomically), so a relational database sharded by user or workspace fits well. Blocks are immutable, and named by hash, so object storage is perfect.
| Technique | What it gives you |
|---|---|
| Chunking (~4 MB blocks) | Resumable and parallel uploads |
| Delta sync (hash compare) | Only changed blocks travel |
| Deduplication (hash = name) | Identical blocks stored once, across files and users |
| Compression | Smaller uploads for text-heavy files |
| Versions as block lists | Cheap history: old versions share most blocks |
Step 5 · Scale and reliability
- Durability: object storage keeps several copies across data centres (or uses erasure coding), so a disk or building failure loses nothing.
- Conflicts: optimistic concurrency: commits include
baseVersion; a stale commit gets 409 and becomes a conflicted copy. - Offline: clients queue changes locally and replay them when back online, then pull changes since their last cursor.
- Garbage collection: when old versions expire, decrement block reference counts and delete blocks nobody uses.
- Sharing: check permissions on every metadata and block request; share links carry signed, expiring tokens.
- Cold data: files untouched for months move to cheaper storage tiers.
🧠 PATH memory card
Remember the file sync design for good
Picture it · Anchor it · Trace it · Hit-recall it. Four quick steps that turn “I read it once” into “I can explain it in an exam”.
- P
Picture it
Your brain remembers scenes far better than definitions.
← swipe to see the whole picture →
Moving house with a clever rule: everything is packed into same-sized boxes labelled by exactly what's inside. If the new house already has an identical box, you don't ship it. A list on the fridge says which boxes make up each room (a version), and when you're done you phone the family so they can collect only the new boxes.
- A
Anchor it
A silly sentence you can't forget, where every word maps to the concept.
“Chop, Hash, Upload only new, Tell the other devices”
- Chop→Split files into ~4 MB blocks
- Hash→Name each block by its content hash
- Upload only new→Delta sync + deduplication via /blocks/check
- List on the fridge→A version = ordered list of block hashes in the metadata DB
- Tell the other devices→Notifier → devices pull changes since their cursor
- T
Trace it
Run it by hand on a tiny example once. Doing beats reading.
Edit page 30 of a 40 MB Report.docx. Chop into 10 blocks. Hash: block #4 changed. Check: server is missing only #4 → upload 4 MB. Commit version 8 from base 7 → OK. Notify: phone gets “changes since c_5512”, downloads block #4, rebuilds the file. If the phone had committed v8 first → 409 → conflicted copy. - H
Hit-recall it
Test yourself now, then again on the day each card comes back.
Card 1 / 8 · new0 mastered · 0 practisedSay the answer out loud first, then flip and be honest.
Follow-up questions interviewers ask
- “Fixed-size or variable-size chunks?” Fixed is simpler. Inserting a byte at the start shifts every fixed block; content-defined chunking (boundaries chosen by content) keeps most blocks unchanged.
- “End-to-end encryption?” Encrypting on the device protects privacy but makes cross-user deduplication impossible, a real trade-off.
- “Huge folders shared with thousands?” Store permissions on the folder and inherit them, rather than copying a permission row for every file.
Where to go next
Files sit still. Taxis don't. Next, a system that tracks a million moving cars and matches them to riders in seconds: design Uber.
Key takeaways
- ✓Split files into blocks named by content hash.
- ✓Upload only missing blocks: delta sync plus deduplication.
- ✓Blocks go to durable object storage; files, versions, block lists and permissions go to a metadata DB.
- ✓A notifier tells other devices to pull changes since their cursor.
- ✓Detect conflicts with base versions and keep a conflicted copy; never lose an edit.
Frequently asked questions
How does Dropbox or Google Drive sync files?
The desktop or phone app watches a folder for changes. When a file changes, the app splits it into blocks of a few megabytes, computes a hash for each block, uploads only blocks the server doesn't already have, and then commits a new version: the ordered list of block hashes. The server notifies your other devices, which download just the changed blocks and rebuild the file.
Why split files into chunks?
Chunking makes uploads resumable (a dropped connection only loses one block), lets changed parts of a big file sync without re-uploading the rest, allows blocks to be uploaded in parallel, and enables deduplication: identical blocks, even across different files or users, only need to be stored once.
What is deduplication in cloud storage?
Deduplication means storing identical data only once. Because blocks are named by the hash of their content, two identical blocks have the same name. Before uploading, the client asks whether the server already has that hash; if it does, nothing is uploaded and the new file simply points to the existing block. This saves a lot of storage and bandwidth.
How are sync conflicts handled?
Every commit says which version it was based on. If two devices edit the same file offline and both try to commit on top of the same version, the server accepts the first and rejects the second. Instead of silently overwriting, the second device's edit is saved as a separate 'conflicted copy' so no work is lost. Real-time editors like Google Docs avoid this by merging edits live.
How does Google Drive know when another device changed a file?
Clients keep a long-lived connection to a notification service (long polling or a WebSocket). When a commit happens, the service tells the user's other devices that something changed; they then ask the metadata service for changes since their last sync cursor and download any new blocks.
🧠 Quick check: file sync
1. You change one slide in a 200 MB presentation split into 4 MB blocks. What uploads?
2. Two users upload the same 1 GB movie file. With content-hash deduplication, how much is stored?
3. Where do file names, folders and versions live?
4. Laptop and phone both edit Report.docx offline from version 7. What's the safest outcome?
Checking your access…