Design Dropbox (File Sync) — System Design Interview Walkthrough
"Design Dropbox" looks like a storage problem and is actually a synchronisation problem. The bytes are the easy half: chunk the file, put the chunks in an object store, hand out signed URLs, done. The hard half is that every device holds its own copy of a mutable file tree, goes offline whenever it likes, and comes back expecting to be told exactly what changed while it was away — without walking the whole tree to find out.
Candidates who spend the interview on object storage and CDNs stall. The question is won on the metadata path: how a change becomes an ordered, durable, resumable fact that four devices and two collaborators can each catch up to independently. This walkthrough covers the requirements worth pinning down, the arithmetic that forces the architecture, chunking and content addressing, the journal-and-cursor model that makes sync a range scan, how conflicts are actually detected, and what the whole design still cannot do.
Requirements worth pinning down
Functional
- A client watches a local folder and uploads what changed.
- A change on one device appears on the user's other devices without the user doing anything.
- Files are versioned; a deleted file can be restored for some retention window.
- A folder can be shared with other users, who then see each other's changes.
Non-functional
- Durability is the top priority. Losing a file is unforgivable; showing a file ten seconds late is fine. That asymmetry is the single most useful thing to state early, because it tells you where to spend consistency: the metadata commit is atomic and durable, propagation to other devices is eventual.
- Bandwidth efficiency at the client. Users are on hotel Wi-Fi and metered LTE.
- Offline tolerance. A week offline must resolve into a correct tree, not a resync.
Descope two things out loud. Real-time collaborative editing is a different problem with a different data model — that is Google Docs, and the answer there is operational transforms or CRDTs over a structured document, not a better file-sync protocol. Full-text search and previews are a downstream consumer of the change stream, not part of sync.
The arithmetic that shapes the design
Four numbers decide most of the architecture. Take 50 million daily active users, two devices each, and 50 file changes per user per day.
Metadata write rate. 50 M × 50 = 2.5 B commits/day. 2.5 × 10⁹ / 86,400 ≈ 29,000 commits/s average, call it 90,000/s at a 3× daily peak. That is far past one relational primary, so the metadata store is sharded from day one.
Byte ingest, naively. If the average changed file is 1 MB and the client re-uploads whole files, that is 2.5 PB/day: 2.5 × 10¹⁵ / 86,400 ≈ 29 GB/s, roughly 230 Gbps sustained. Cutting that by 5–10× with block-level diffs is the difference between an ingest tier you can afford and one you cannot.
Metadata size. A 100 GB account at 4 MB blocks is 25,000 blocks; at 32 bytes per SHA-256 digest that is 800 KB of block pointers per account, before paths, versions, or sharing rows. Across 50 M accounts: ~40 TB of pointers alone. The file list is itself a large database.
Live connections. 100 M devices, maybe 40% online at once → 40 M concurrent clients that each want to know when something changed.
Those four push you to three decisions before you have drawn anything: the metadata tier is sharded, the bytes must not pass through it, and the client must send diffs rather than files. If you want to practise generating numbers like these on the fly, the back-of-the-envelope estimation post drills the method.
Split the system along the plane that matters
The first real design move is to separate the control plane from the data plane. Metadata commits are small, transactional, and ordered. Blocks are large, immutable, and need no ordering at all. Running both through the same service means your transactional database sits in the path of 230 Gbps of file bytes.
The upload then becomes three steps, and the ordering of them matters:
1 POST /blocks/probe {"hashes": ["9f2a…","c31b…","7de4…","0a55…","b182…"]}
200 {"missing": ["7de4…"]}
2 PUT /blocks/7de4… <4 MB of bytes> # idempotent: key is the content
200 {"stored": true}
3 POST /commit {"path": "/decks/q3.pptx",
"parent_rev": 4172,
"blocks": ["9f2a…","c31b…","7de4…","0a55…","b182…"]}
200 {"rev": 4180}
Blocks are uploaded before the commit, never after. The commit is the only thing that makes the new version visible, so a client that dies mid-upload leaves orphaned blocks — garbage, collected later — rather than a file whose metadata points at bytes that do not exist. Get this order backwards in an interview and you have described a system that can serve a corrupt file.
Both of the first two calls are naturally idempotent because the key is the content hash: retrying a PUT after a timeout is free. The commit is the step that needs an explicit guard, which is what parent_rev provides — see idempotency and safe retries for why a timeout tells the client nothing about whether the write landed.
Chunking: fixed blocks or content-defined?
Dropbox splits files into 4 MB blocks and hashes each with SHA-256. Fixed-size blocking is trivial to implement and gives you the probe-then-upload protocol above for free. It has one sharp failure: it is not resilient to insertion. Add two kilobytes at the head of a file and every subsequent block boundary shifts by two kilobytes, so every block hash changes, and the client re-uploads the entire file despite 99.99% of the bytes being unchanged.
Content-defined chunking fixes this by letting the data choose the boundaries. Slide a window over the bytes, keep a rolling hash of it, and cut wherever that hash hits a fixed pattern:
MASK = (1 << 22) - 1 # average chunk ≈ 4 MiB
for byte in stream:
h = roll(h, byte) # rolling hash of the trailing 48-byte window
window.append(byte)
if h & MASK == 0 or len(window) >= MAX_CHUNK:
emit_chunk(window) # boundary depends on content, not offset
window.clear()
Because the boundary depends only on the bytes immediately around it, inserting data shifts one chunk and leaves every later chunk — and therefore every later hash — identical.
| 20 MB file | Fixed 4 MB | Content-defined | Whole file |
|---|---|---|---|
| Re-upload after head insert | 20 MB | ~4 MB | 20 MB |
| Re-upload after append | 4 MB | ~4 MB | 20 MB |
| Client CPU | 1 hash pass | rolling + hash | 1 hash pass |
| Cross-version dedup | appends only | general | none |
| Complexity | trivial | moderate | trivial |
What I would actually do: ship fixed 4 MB blocks first. The dominant real workload is appends and whole-file rewrites by applications that rewrite the file anyway (Office, Keynote, Photoshop), and fixed blocking already handles the append case. Content-defined chunking is the right answer when you are optimising for large files edited in place — backup tools like restic and borg use it for exactly that reason — but it costs client CPU on every scan and complicates nothing less than your entire block index. Saying "fixed blocks, and here is the specific workload that would make me switch" is a stronger answer than reciting Rabin fingerprints.
Content addressing, dedup, and the attack it enables
Because a block's key is its own hash, storage is content-addressed: identical bytes are stored once no matter who uploads them. Dropbox's public content hash is defined exactly this way — SHA-256 of each 4 MB block, the digests concatenated, then hashed again:
import hashlib
BLOCK = 4 * 1024 * 1024
def block_hashes(path: str) -> list[str]:
out = []
with open(path, "rb") as f:
while chunk := f.read(BLOCK):
out.append(hashlib.sha256(chunk).hexdigest())
return out
def content_hash(hashes: list[str]) -> str:
joined = b"".join(bytes.fromhex(h) for h in hashes)
return hashlib.sha256(joined).hexdigest() # identity of the whole file
That one function gives you four things: change detection without reading the server's copy, resumable uploads, cross-version dedup, and an end-to-end integrity check the client can verify itself.
The interesting part is the scope you dedup across. Cross-user dedup is where the savings are — every employee at a company has the same onboarding PDF — but it creates a side channel. If the probe step tells any user whether an arbitrary hash already exists, the server has published an oracle for "does this exact file exist in the system", which leaks the presence of specific documents. Worse, if possession of a hash is accepted as proof of possession of the bytes, then a leaked hash is a download token: an attacker who learns the hash can commit it into their own account and fetch a file they never had. Published attacks on Dropbox-style dedup in 2011 turned on exactly this.
The fix is to scope dedup to a trust boundary you are willing to defend — per user, or per team — and to never treat a hash as an authorisation. Keep an explicit record of which namespaces have legitimately uploaded a block, and serve bytes only against that record. You give up some of the savings; you no longer have a cross-tenant information leak. For an interview, naming this trade-off unprompted is a strong signal, because it shows you understand that dedup is a security decision rather than a storage optimisation.
The metadata journal is the real database problem
Here is the core of the system. Each namespace — a user's root, or a shared folder — owns a strictly monotonic revision counter. Every committed change appends one entry to that namespace's journal and takes the next revision number. A client stores one integer per namespace: its cursor, the highest revision it has applied.
Sync is then one question, asked over and over: give me everything after my cursor.
Interviewers probe why the cursor is not a timestamp, and the answer is worth having ready. Client clocks are wrong, sometimes by minutes. Two commits can share a millisecond, so WHERE modified > :t either re-sends or skips entries at the page boundary depending on whether you use > or >=. And a timestamp gives no total order, so two clients can legitimately disagree about what happened first. A server-assigned, gap-free sequence per namespace removes all three problems at once. Serve the delta as a paginated scan with an opaque cursor token, so you can change the representation later without breaking old clients:
SELECT rev, path, op, blocks FROM journal
WHERE namespace_id = :ns AND rev > :cursor
ORDER BY rev LIMIT 1000;
Shard by namespace, not by user. This is the detail that catches people. Sharding by user_id is the obvious first answer and it breaks the moment folders are shared: a folder visible to eight users cannot have a single home if the shard key is the user. Make the namespace the unit of sharding and of ordering; a user's view is then an assembly of the namespaces they can see, each with its own cursor. The trade-off is that you lose a global order across namespaces — a file moved from one shared folder to another can briefly appear in both or neither — which is a real anomaly you should name rather than hide. Database sharding covers why picking this key wrong is so expensive to undo.
Change notification: I would long poll
40 million devices need to learn that something changed. The thing to notice is how little information they need: not the change, just the fact that one exists. One bit, and then the client runs the delta query it already knows how to run.
That asymmetry is what makes long polling the right choice here, and I would defend it over WebSockets. The client opens a request carrying its cursor, the server holds it for up to a minute, and replies either "changed" or "nothing, ask again". Dropbox's public API exposes precisely this shape: /files/list_folder/longpoll takes a cursor and a timeout between 30 and 480 seconds, and returns {"changes": true} — not the changes themselves. Three reasons that beats a persistent bidirectional socket for this job:
- There is no client-to-server push requirement. Uploads are ordinary HTTP requests. A full duplex channel buys nothing.
- A stateless one-bit responder can be sharded by namespace and redeployed without anyone noticing, because a dropped long poll is indistinguishable from a timeout — the client just reconnects. Dropping 40 M WebSockets during a deploy is a thundering-herd event.
- It traverses every corporate proxy and captive portal unchanged, which matters more than elegance for a desktop client.
The cost is up to one wasted round trip per minute per idle device and a reply latency bounded by nothing worse than your hold time. The general comparison — including when a socket genuinely does earn its keep — is in WebSockets vs SSE vs long polling. File sync is the clearest case I know of where the simplest transport is the correct one.
Conflicts are detected by compare-and-set, not by mtime
Two devices edit the same file while both are offline. Both come back. What happens?
The mechanism is already in the commit: parent_rev. A commit says "I am basing this on revision 4172". The server compares that against the file's current revision inside the transaction and rejects with a conflict if they differ. This is optimistic concurrency control — a compare-and-set on the metadata row — and it is the precise answer to "how do you detect a conflict". Not modification times, which are unreliable and unordered. Not content hashes, which tell you the files differ but not which is the ancestor.
Then you have to decide what to do, and there are only three options:
- Last write wins. Whichever commit the server happens to process second overwrites the other. Silent data loss, which for a product whose promise is "never lose a file" is disqualifying.
- Merge. Impossible in general. You cannot merge two versions of a 40 MB binary, and you must not guess.
- Keep both. Accept one commit as the new revision and have the losing client re-commit its version under a new path:
q3 (conflicted copy 2026-11-16).pptx.
Keep both is the right answer, and it is right for an unglamorous reason: it converts an unsolvable data problem into a visible user-interface problem. A human looks at two files and decides, which is the only thing that can actually resolve a semantic conflict. Say that out loud in an interview — the reasoning matters more than the mechanism.
Two sharp edges worth mentioning if you have time. Directory conflicts are harder than file conflicts: one device renames /reports, another adds /reports/new.pdf, and resolution has to rebuild a tree, not pick a file. And case sensitivity is a genuine production problem — Foo.txt and foo.txt can coexist on Linux and cannot on macOS or Windows, so the server has to enforce the most restrictive rule or a sync will fail forever on one platform with no way for the user to fix it.
What this design does not solve
Real-time collaborative editing. Nothing here lets two people type in the same document at once. The unit of change is a file version; co-editing needs the unit to be an operation on a structured document. Different data model, different system.
Large files mutated in place. A 50 GB VM image, a SQLite database, or an Outlook mailbox file is written to constantly in scattered places. Content-defined chunking limits the re-upload to the touched chunks, but you still pay a full read-and-rehash scan per save, and if you retain versions you store a new chunk set each time. The honest answer is that such files should not live in a sync folder.
Many tiny files. node_modules or a .git directory is a metadata problem wearing a storage costume. One npm install can create 100,000 files — more commit operations than that user generates in a normal year — while moving almost no bytes. The byte path yawns; the metadata tier is what falls over. Rate limiting per namespace and ignore rules are mitigations, not fixes.
Sync is not backup. The system faithfully propagates deletions and encryption-in-place, which means ransomware replicates perfectly to every device. Version history plus a retention window is the actual protection, and it costs storage you must budget for.
Client disk space. Full sync means the smallest device bounds the account. On-demand hydration — placeholder files that fault in on open — fixes it, but requires a filesystem extension on every platform and is a far larger engineering project than the sync protocol itself.
Cross-namespace ordering, as above: per-namespace sequences give no global order, so moves between shared folders have observable anomalies.
The alternatives worth naming
rsync (Tridgell, 1996) solves a related problem differently: a rolling checksum lets the sender diff against the receiver's copy with no server-side index at all. No per-account metadata, no block store, no journal. It is the right tool for mirroring one tree to one place, and the wrong tool for fan-out to five devices, because every pair re-derives the diff from scratch.
Git is also content-addressed, but it tracks a history DAG and is merge-aware for text. If the unit of change is a text hunk and users expect explicit merges, you want git's model, not Dropbox's. It is a poor fit for large binaries, which is why git-lfs exists.
Peer-to-peer block exchange (Syncthing, and the general BitTorrent-style approach) drops the central metadata authority: devices exchange block indexes directly. That removes the metadata tier as a bottleneck and the provider as a trusted party, and it gives up the single authoritative order — so conflicts are more frequent and reconciliation is murkier. A reasonable answer if the interviewer adds "and I do not want to trust a server".
Object storage with versioning alone — S3 plus a thin client — is adequate for backup and inadequate for sync. No cursor, no change notification, no conflict story. If someone proposes it, the question to ask is how a second device finds out anything happened.
Answering it in an interview
The order that lands best:
- Reframe the question. "The bytes are an object store. The hard part is the metadata: an ordered, durable change log each device can catch up to independently."
- Do the arithmetic. Commits per second and bytes per second, out loud, because those two numbers are what force the split between the control and data planes.
- Describe the three-step upload, and say explicitly that blocks land before the commit, so a partial upload leaves garbage rather than a corrupt file.
- Introduce the journal and cursor, and say why it is a sequence rather than a timestamp. This is the part most candidates never reach, and it is the heart of the system.
- Shard by namespace, and volunteer that this is what makes shared folders work and what costs you global ordering.
- Pre-empt the conflict follow-up. Compare-and-set on
parent_revfor detection, conflicted copies for resolution, and the reason: a human is the only thing that can resolve a semantic conflict.
If you can also say which chunking strategy you would ship first and what workload would change your mind, you are answering as an engineer who has had to make the call rather than one who has read about it. Practising that distinction out loud — with an interviewer pushing back on the chunking decision — is worth more than another read-through; you can run this problem as a spoken system design mock on Whitepad and find out which parts of it you can only write down.
Practice this out loud
Reading is the easy part. Sit across from a senior AI interviewer that talks, watches your whiteboard, and scores you like the real thing — your first mock is free.
Start a free mock →