Design Dropbox - a personal cloud drive that keeps files and folders in sync across a user's devices. Devices go offline for minutes or weeks, uploads break at 95%, and two devices save the same file. The staff-level signal is making the commit the only moment a change becomes true, treating the ordered change feed as the truth and a push as a hint, and never losing a user's bytes without telling them.
Written by a Staff+ Engineer and an Engineering Manager
12+ years of experience in distributed systems and real-time messaging. Tech lead for large-scale chat applications serving billions of users. Over 12 years of industry experience with 6 years in engineering leadership, building and scaling tech infrastructure teams that deliver end-to-end large-scale distributed systems.
Finished this lesson?
Sign in to save your progress across devices.
Tip: use ← and → to move between lessons.
Was this lesson helpful?
Rehearse this exact question with the author
45-minute mock with a Staff+ engineer who interviews at your target company. Premium members save $20.
What to Design?
Could you answer these today? Tick what you already know.
The happy path is quick to draw: a client, an API, a database for folders, a store for bytes. The interview is decided by four questions about a device that was not there when something happened. Each one is a deep dive below, with three designs side by side.
Swipe to see all columns
| The four questions, and the answer that sounds right | |||
|---|---|---|---|
| # | The interviewer asks | The answer that sounds right | What it misses |
| DD1 | The phone was in a tunnel for 20 minutes. How does it find out what changed? | The server pushes every change to the device | A push can be lost, and nothing tells the phone that it missed one |
| DD2 | Two devices edit the same file offline. Both reconnect. What is in the folder? | The newer save wins | The other edit disappears on every device, and nobody is told |
The same three habits answer all four:
Do not spend your questions on API details. Spend them on what the product promises when devices disagree.
Swipe to see all columns
| Scope Decisions | ||
|---|---|---|
| Question | Agreed answer | Why it matters |
| What are we building? | A personal drive: one owner, several devices. No sharing, no live co-editing | No merge algorithms. The hard part is sync between devices that go offline |
| Two devices edit the same file offline? | Both versions survive. One keeps the name, the other becomes a visible conflict copy | A save must say which version it started from (DD2) |
| How does a device learn of a change? | A push may wake it up. The truth is an ordered feed that it reads from its own position | |
Out of scope (say this out loud): live co-editing, search and previews, shared folders and team permissions, metadata that is writable in several regions, device-to-device sync on a local network, and end-to-end encryption, which would hide the hashes that dedup needs.
FR1 — Files and folders. Create, rename, move, list and delete files and folders under one personal root.
FR2 — Upload. Large files upload in resumable sessions. After a broken connection only the missing parts are sent.
FR3 — Download. A device downloads a named version of a file. It can fetch a range of it and resume.
FR4 — Sync. A device asks for the changes since its position, in order, and applies them. Applying a change twice is harmless.
FR5 — Conflicts. Two saves of the same file from the same version keep both. The later one becomes a conflict copy.
The key principle behind all five
Swipe to see all columns
| Five facts and the conclusions they do not supportRead each row as: the fact on the left does not, by itself, imply the claim in the middle. | ||
|---|---|---|
| Fact | Does not imply | Why the gap exists |
| The chunks are uploaded | The file exists | A file exists when its commit is done. Until then the chunks belong to an upload session |
NFR1 — Consistency. The folder tree, the versions and the order of changes are strongly consistent. A change that was confirmed is never lost.
NFR2 — Speed. p99 under 200 ms to list a folder, commit and read the feed. Under 300 ms to open an upload session, which has to look up every chunk hash. Moving bytes is limited only by the network.
NFR3 — Scale. 10 million daily users, 30 million devices, 20,000 metadata writes and 100,000 reads a second at peak.
NFR4 — Cost. Identical blocks are stored once: 60 PB in place of 200 PB.
NFR5 — Nothing is lost silently. An upload resumes, a conflict keeps both versions, and a delete can be undone for 30 days.
| Capacity Thought Experiment | |
|---|---|
| Parameter | Value |
| Accounts | 50 million, of which 10 million are active on a day |
| Files | 1,000 per account at 4 MB on average: 50 billion files, 200 PB |
| After dedup | 60 PB, about 15 billion unique chunks of 4 MB. 70% is saved |
| File size | 4 MB on average, which is one chunk. 500 MB at p99, which is 125 chunks |
| Devices | 3 per active user: 30 million online |
The number that identifies the real system is not a size. It is a count of copies:
metadata ~30 TB must be exactly right: every change is a transaction and a line in the feed
bytes ~60 PB 2,000 times more, stored and fetched by hash
devices 30 million each one holds a copy of a folder, and each copy must end up the same
Storing the bytes is a solved problem. Keeping 30 million copies in step, when any of them can be offline, is the design. Every number above is an illustrative assumption.
Interviewer signal: candidates who draw "client, server, storage" and spend the hour on chunking have built a backup tool. Candidates who say "every device is a copy that follows one ordered list of changes, and the commit is what writes that list" have found the system.
Three ideas shape everything:
Metadata is 30 TB and decides everything: which files exist, which version is current, what changed and in which order. Bytes are 60 PB and decide nothing. So metadata gets a transactional database, and bytes get a simple store that knows only hashes. The commit is the one place where the two meet.
A file is cut into 4 MB chunks, and each chunk is named by the hash of its bytes. A version, called a revision, is an ordered list of those hashes: its manifest. A manifest never changes. An edit creates a new revision that lists mostly the same chunks, so only the chunks that differ are uploaded.
Each change of a user's drive gets the next number in that user's own sequence. A device remembers the last number it has applied: its cursor. To sync, it asks for everything after the cursor and applies it in order. That works after a minute offline and after a week.
The core recognition
This is a small transactional metadata store with a change log per user, in front of a content-addressed chunk store. Content-addressed means: a chunk is found by the hash of its bytes. One commit transaction publishes a revision and appends the log line that announces it. Devices are followers of that log.
| Design Decisions | |
|---|---|
| Design choice | Reason |
| 4 MB chunks, named by their SHA-256 hash | An edit uploads only the chunks that changed, and identical content is stored once |
| An upload session with states and an expiry | An upload can resume, and its leftovers have an owner (DD3) |
Five tables carry the design. The two fields to explain are
head_revon a node, which every save is checked against, andchange_seqon a feed event, which every device follows.
One row per file or folder. The id never changes: not on a rename, not on a move, not on a new revision.
Swipe to see all columns
| nodes | ||
|---|---|---|
| Field | Type | Comment |
node_id | STRING | Primary key, for example N-7 |
user_id | STRING | The owner. All rows of one drive live together |
One row per saved version of a file.
Swipe to see all columns
| revisions | ||
|---|---|---|
| Field | Type | Comment |
node_id, rev_no | STRING, INT | Primary key together. 1, 2, 3 in the order of the commits |
manifest | LIST | |
One row per unique block of content.
Swipe to see all columns
| chunks | ||
|---|---|---|
| Field | Type | Comment |
chunk_hash | STRING | Primary key. SHA-256 of the bytes, shown here by its first four characters |
size | INT | Bytes, at most 4 MB |
reference_count | ||
An upload in progress. It owns its parts until the commit.
Swipe to see all columns
| upload_sessions | ||
|---|---|---|
| Field | Type | Comment |
session_id | STRING | Primary key, for example S-1. Committing the same session twice gives the same answer |
user_id, target | STRING | An existing node_id |
One row per change of a drive. Together they are the change feed.
Swipe to see all columns
| sync_events | ||
|---|---|---|
| Field | Type | Comment |
user_id, change_seq | STRING, INT | Primary key together. A counter per user: 41, 42, 43. No gaps, no ties |
type | ENUM | |
Swipe to see all columns
| Supporting records | ||
|---|---|---|
| Record | What it holds | Why it exists |
| User | user_id, quota, last_seq | last_seq is the counter behind change_seq. A commit raises it in its own transaction |
| Device | device_id | |
Swipe to see all columns
| Storage | ||
|---|---|---|
| Store | Data | Consistency |
| PostgreSQL | nodes, revisions, chunks, upload_sessions, sync_events, users, devices | Strong, transactional. The source of truth |
| Blob store | Chunks, named by their hash | No logic. It keeps three copies of every chunk by itself |
| The device's own disk | The cursor, and for each file the revision and chunks it holds | Disposable. It can be rebuilt from a full listing |
The blob store is an object store of its own. How it places copies and frees space is the subject of S3-like Object Storage. Here it is one box.
Swipe to see all columns
| Files and folders | ||
|---|---|---|
| Endpoint | Request | Response |
GET /nodes?parent_id= | A folder | Its children: name, type and current revision |
POST /nodes | A parent and a name | 201: a new folder |
PATCH /nodes/{id} | A new name or a new parent, and | |
Swipe to see all columns
| One upload is three calls | ||
|---|---|---|
| Call | Request | Response |
1. POST /upload_sessions | The target, the size, and for each chunk its index, hash and size | Session S-1, valid 7 days. Per chunk: stored, or a presigned PUT URL valid 15 minutes |
2. PUT {presigned URL} | The bytes of one chunk, sent straight to the blob store | 200 when the chunk is stored |
Swipe to see all columns
| Sync | ||
|---|---|---|
| Endpoint | Request | Response |
GET /sync/changes?cursor=41 | The last change number the device has applied | Up to 500 events in order, next_cursor and has_more. 410 when the cursor is older than 30 days |
GET /sync/snapshot | No body | The full listing of the drive, and the change number it is valid for. Used after a 410 (DD4) |
A presigned URL is a link that carries its own permission: which chunk, which method, until when, and a signature. The blob store checks it without calling anyone.
Present the design as four short stories, each in its own colour on one whiteboard: Phase 1 upload (black), Phase 2 sync (blue), Phase 3 edit (green), Phase 4 delete (purple). Every story has six numbered steps. The number on an arrow is the same number in the animation and in the step table.
Swipe to see all columns
| The four phases | |||
|---|---|---|---|
| Phase | Colour | Story | What it leaves behind |
| Phase 1: Upload (FR2) | Black | Alice's laptop saves a new 10 MB file, /Work/plan.docx | Node N-7 at revision 1. Three chunks. Feed event 41 |
| Phase 2: Sync (FR3, FR4) | Blue | Alice's phone finds out and downloads the file | The phone has the file and cursor 41 |
How to read the picture
/Work/plan.docx: node N-7, 10 MB, chunks b7e1, 4d90 and c35a.Each phase below is an interactive walkthrough of the same picture. It plays on its own. You can pause it, step with the arrow keys, and click any component to read its role.
Goal: get the bytes into the blob store without passing the gateway, and make the file appear in one step.
/upload_sessionsLaptop → API gateway → Metadata serviceNothing is written in this step.
Swipe to see all columns
| Phase 1 step by step (black arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | The laptop cuts the file into 4 MB chunks and hashes each one. It sends POST /upload_sessions with the folder N-3, the name, the size and the three hashes. | Nothing yet |
| 2 | The metadata service looks the hashes up in chunks. None is stored. It opens a session. | Session S-1, CREATED |
Why it is built this way
Then the folder shows a file with no content, on every device, for as long as the upload takes. If the upload dies, the empty file stays until someone cleans it up. With the commit last, there is one moment at which the file starts to exist, and before it nothing is visible.
Goal: bring the phone to the same state, with the phone in charge of its own position.
drive changedMetadata service → Notifier → PhoneNothing is written in this step.
Swipe to see all columns
| Phase 2 step by step (blue arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | After the commit the notifier pushes a hint to the phone: Alice's drive changed. It carries no file data. | Nothing |
| 2 | The phone sends GET /sync/changes?cursor=40. | Nothing |
| 3 | The metadata service reads Alice's events above 40, in order. It returns event 41: node N-7, /Work/plan.docx, revision 1, 10 MB. | |
Why it is built this way
Because only the device knows what is really on its disk. A phone can be restored from an old backup, or the app can be reinstalled. A position stored on the server would then be wrong, and the phone would skip changes without noticing. A cursor that the device keeps next to its files is always honest.
Goal: save a new version by moving only the bytes that changed, and prove that the save started from the current version.
/upload_sessionsLaptop → API gateway → Metadata serviceNothing is written in this step.
Swipe to see all columns
| Phase 3 step by step (green arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | The laptop hashes the edited file. Chunk #2 has a new hash, e2f8. It sends POST /upload_sessions for node N-7 with the hashes b7e1, 4d90, e2f8. | Nothing yet |
| 2 | The metadata service finds b7e1 and 4d90 in chunks. Only e2f8 is new. | Session S-2 |
Why it is built this way
A phone may be in the middle of downloading revision 1. If its chunk list could change under it, the phone would join chunks of two versions into a file that never existed. A manifest that never changes makes every download stable, and it makes the counts exact: a chunk is in use as long as some revision lists it.
Rename and move (FR1) change one row: the node's name or its parent_id, with the same base check and one feed event. Moving a folder with 100,000 files is still one row, because a child points at its parent. A move into the folder's own subtree is refused. Listing a folder is one index read on parent_id.
Goal: make the file disappear on every device at once, keep it restorable for 30 days, and free the bytes only after that.
/nodes/N-7Laptop → API gateway → Metadata serviceNothing is written in this step.
Swipe to see all columns
| Phase 4 step by step (purple arrows) | ||
|---|---|---|
| Step | What happens | Data written |
| 1 | The laptop sends DELETE /nodes/N-7 with base_rev 2. | Nothing yet |
| 2 | One transaction marks the node and writes the feed event. The revisions and the chunks are not touched. | N-7: deleted_at set. last_seq |
Why it is built this way
Because a delete is the change that users regret most often, and a sync product deletes on every device at the same moment. Without the window, one wrong click on the phone destroys the file everywhere. The tombstone costs one row, and the bytes cost storage for 30 days. That is the price of an undo.
The deep dives are the four questions from the top of the page. Each one compares three designs for the same scenario: a Bad one, which is usually the answer that sounds right; a Good one, which still leaves a gap; and a Great one, which holds. The answers start covered. Read the scenario, decide what you would build, then click each card.
Swipe to see all columns
| Deep Dive Map | |||
|---|---|---|---|
| Deep Dive | Topic | Scenario | NFR |
Scenario: Alice's phone is in a tunnel from 09:00 to 09:20. Its cursor is 41. In that time her laptop commits three changes: 42 edits plan.docx, 43 adds budget.xlsx, 44 renames plan.docx to plan-v2.docx. At 09:20 the phone is online again. What does it show?
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. After each commit the server pushes the change to the user's other devices. A device applies what it receives.
Where it breaks. A push is best effort. While the phone is offline, the push service keeps only the newest message for it. At 09:20 the phone receives change 44 and applies the rename. It never hears of 42 and 43, and nothing tells it that two changes are missing. Its folder is wrong from then on.
The idea. Every change is a row in the feed, written by the commit. Every 5 minutes a device asks for the changes after its cursor.
What it fixes. Correctness. At 09:20 the phone asks with cursor 41 and gets 42, 43 and 44 in order. No outage can make it miss a change.
What it still misses. Cost and delay. 30 million devices polling every 5 minutes are 100,000 requests a second, and nearly all of them return nothing. A change still waits up to 5 minutes.
The key idea. The push says when to ask. The feed says what changed. A hint can be lost without harm, because the device also asks on its own.
How it works
GET /sync/changes?cursor=41.next_cursor.The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure.
/upload_sessions/{id}/commitLaptop → API gateway → Metadata service200: plan.docx, rev 2N-7updateSwipe to see all columns
| DD1 side by side | |||
|---|---|---|---|
| Bad: push only | Good: poll with a cursor | Great: hint and feed | |
| The phone at 09:20 | Has change 44 only | Has 42, 43 and 44 | Has 42, 43 and 44 |
| Delay while the phone is online | About a second | Up to 5 minutes | About a second |
Check it against the scenario
| The phone after the tunnel | |
|---|---|
| Situation | Outcome with the Great option |
| All three hints are lost | The phone asks when it reconnects and gets 42, 43, 44 |
| The answer with the three events is lost on the way | The cursor is still 41. The phone asks again and gets the same events |
| The phone crashes after applying 42 | It restarts at cursor 41 and applies 42 again. Nothing changes |
| The phone was off for 60 days | Its cursor is older than the feed. It gets 410 and resyncs (DD4) |
The trade-off to name. There are two paths to keep working: the push for speed and the feed for truth. And every event must be safe to apply twice. In exchange, a lost push costs seconds and nothing else.
Two commits can carry the same millisecond. And a transaction that started early can finish late and still carry the earlier time. A device that has already read past that time never sees the change. A counter has neither problem if it is handed out in the order of the commits. Here it sits on Alice's user row and is raised inside the commit transaction. The lock on that row makes her commits wait for each other, so the numbers have no ties and no gaps. One person's drive sees a few writes a second at most, so the queue is short.
"Every commit writes the change and one feed row in the same transaction. The feed is ordered per user by a counter that the commit raises. Each device keeps a cursor, the last number it applied, and asks for everything after it. It applies events idempotently and saves the cursor afterwards, so a repeated batch does no harm. Push is only a hint to ask sooner. If it is lost, the device asks on reconnect or on a slow timer. So push decides when a device asks, and the feed decides what it gets."
Follow-up: "One device is 200,000 changes behind. What happens?" — It reads pages of 500 in order. The server may slow it down, but it never skips a range. Past some size a full listing is cheaper, and the server answers "resync", as for an expired cursor.
Scenario: This is Phase 3 with a twist. The laptop and the phone both hold revision 1 of plan.docx, and Alice edits it on both while they are offline. The laptop reconnects at 14:00 and commits. The phone reconnects at 14:05 and commits its own version. What is in /Work afterwards?
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. A commit creates the next revision. Whoever commits last is the current version.
Where it breaks. The laptop's commit becomes revision 2. Five minutes later the phone's commit becomes revision 3. The laptop reads the feed and replaces its file with the phone's. The laptop's edit is gone on every device, and nobody was told.
The idea. A commit names the revision it started from, its base_rev. If that is not the head any more, the server answers 409 Conflict.
What it fixes. The server never overwrites. The laptop's revision 2 is safe.
What it still misses. The phone's edit now exists only on the phone, and what happens next is up to the app. One app version retries with base_rev 2 and overwrites the laptop's edit: last write wins again. Another saves its own copy under a name it made up. Devices end up disagreeing about what a conflict looks like.
The key idea. A stale commit is not an error. It is a second version that needs a place. The server gives it one, in the same transaction that notices the conflict.
How it works
base_rev 1. The head goes from 1 to 2. Feed event 42.base_rev 1.plan (conflicted copy, Phone).docx. Its revision 1 lists the phone's chunks. Feed event 43.The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure.
No call in this step.
local fileupdatelocal fileupdateSwipe to see all columns
| DD2 side by side | |||
|---|---|---|---|
| Bad: last write wins | Good: reject the stale commit | Great: conflict copy | |
| The laptop's edit | Gone from the current version | Kept as revision 2 | Kept as revision 2 of plan.docx |
| The phone's edit | The current version | Only on the phone, until an app decides | Kept as the conflict copy N-8 |
Check it against the scenario
| Two saves of plan.docx | |
|---|---|
| Situation | Outcome with the Great option |
| The answer to the phone's commit is lost | The phone commits S-3 again. The session is already COMMITTED: the same answer, the same N-8 |
| Both commits arrive in the same millisecond | The lock on N-7 puts them in a line. The first keeps the name, the second becomes the copy |
| The phone commits after it has synced revision 2 | A normal commit with base_rev 2: revision 3 |
| The laptop deleted the file while the phone was editing it | The base is stale here too. The phone's edit comes back as a new file |
The trade-off to name. Alice gets two files and has to merge them by hand, and a busy folder can collect copies. The server does not merge: it sees only bytes, and merging would be co-editing. In exchange, no edit is ever dropped, and every device shows the same thing.
Because nobody knows that there is something to look for. The file on the laptop changes under Alice's hands with no sign that her edit was replaced. A version history is where you go when you already know that you lost something. A conflict copy in the folder is what tells you.
"Every commit carries the revision it was based on. The metadata service locks the file's row and compares that base with the head. If they match, the commit becomes the next revision. If they do not, the same transaction creates a sibling file in the same folder, named after the device, with the stale commit's content as its first revision, and writes a feed event for it. The upload session is the idempotency key, so a retry returns the same copy. Both devices then read the feed and show the same two files."
Follow-up: "Why does the server name the copy and not the client?" — One rule in one place. If each app version named its own copies, two devices could disagree about which file is the original.
Scenario: On a train, Alice's phone uploads trip.mp4: 500 MB, which is 125 chunks. The connection drops after 119 chunks, at 476 MB or 95%. What is sent again? And a second question: what if Alice never comes back to finish?
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. The phone sends the file in one request. When the request ends, the file is stored.
Where it breaks. At 476 MB the train enters a tunnel and the connection closes. The server throws the incomplete body away. The phone starts again at byte 0. On a line that drops every few minutes, the upload never ends.
The idea. The phone asks which of its 125 chunk hashes are missing and sends those chunks one by one, straight to the blob store. Then it commits.
What it fixes. The retry. After the drop the phone asks again and sends the last 6 chunks: 24 MB.
What it still misses. An upload that never finishes. Its 119 chunks stay in the blob store with count 0, and no row says which upload they belong to or whether it is still running. A cleanup has to guess, for example "delete chunks that sat at count 0 for 24 hours". That rule also hits an upload over hotel Wi-Fi that has been running for 30 hours. Its first chunks are deleted, and its commit points at bytes that are gone.
The key idea. Every uploaded byte has an owner. Before the commit the owner is the session. After the commit it is a revision.
How it works
POST /upload_sessions with the 125 hashes opens session S-4: CREATED, expires in 7 days.UPLOADING and records each part: 119 of 125. The folder shows nothing.GET /upload_sessions/S-4. The answer: parts 120 to 125 are missing, with fresh URLs.The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure.
trip.mp4, in one requestPhone → API gatewayNothing is written in this step.
Swipe to see all columns
| DD3 side by side | |||
|---|---|---|---|
| Bad: one request | Good: chunks, no session | Great: upload session | |
| Sent again after the drop at 95% | 476 MB, from byte 0 | 24 MB | 24 MB |
| Who owns the chunks before the commit | Nothing is kept | Nobody | Session S-4 |
Check it against the scenario
| The upload of trip.mp4 | |
|---|---|
| Situation | Outcome with the Great option |
| The connection drops after part 119 | The session lists what it has. Six parts are sent |
| A presigned URL expires during the break | GET /upload_sessions/S-4 returns fresh URLs for the missing parts |
| Alice cancels the upload | DELETE /upload_sessions/S-4: the session is ABORTED, and its parts are removed a day later |
| A part of S-4 is also listed by a committed file | |
The trade-off to name. A session is one more row to keep right, with states and a clock. And 7 days is a guess: too short and a slow upload is cut off, too long and abandoned parts cost money for longer. In exchange, cleanup never has to guess.
Because abandoned uploads are normal: an app is closed, a phone is lost, a user changes their mind. If 1 upload in 100 is abandoned half way, that is about 5 TB of parts every day that no file will ever use. The expiry is the rule that lets the system call them garbage without guessing.
"An upload is a session, not a request. The client opens a session with the list of chunk hashes and sends the chunks we do not have straight to the blob store. The session records which parts arrived, so after a break the client asks the session and sends only the rest. Nothing is visible until the commit, which moves the session to COMMITTED in the same transaction that publishes the revision. A session that is not committed within 7 days expires, and a sweeper deletes its parts a day later unless a committed revision or another open session uses them. That cleanup follows the session's expiry, not the reference counts, because those bytes were never visible."
Follow-up: "Can the sweeper delete a part that a commit is about to use?" — A commit checks the session's state inside its transaction and fails on an expired session. The extra day after the expiry covers a commit that started just before it.
Scenario: On day 0 Alice deletes plan.docx on her laptop. Her tablet has been switched off for weeks. It still has the file, and its cursor is 40. On day 30 the trash window ends. On day 50 the tablet is switched on again. What happens to plan.docx?
Three ways to build it. Decide what you would do first. The answers are covered: click a card to reveal it.
The idea. A delete removes the node and its revisions from the database.
Where it breaks. Nothing is left that could tell another device. On day 50 the tablet lists the folder: the server has no plan.docx, and the tablet's disk has one. The tablet cannot tell "deleted on another device" from "created here while offline", so it uploads the file. plan.docx is back on every device. And there was never an undo.
The idea. A delete sets deleted_at on the node and writes a delete event to the feed. After 30 days a purge removes the node, and old feed events are trimmed to save space.
What it fixes. Online devices read the event and remove their copy. Alice can restore the file for 30 days.
What it still misses. A device that was away longer than the feed is kept. On day 50 the tablet asks with cursor 40. Events 41 to 43 are gone, so the server answers with what it still has, from 44 on. The tablet never sees the delete. It keeps plan.docx, finds that the server does not know it, and uploads it.
The key idea. The server never pretends that the feed is complete. A device either reads the delete event, or it is told that its cursor is too old and compares everything.
How it works
deleted_at on N-7 and appends feed event 43.POST /nodes/N-7/restore brings the file back.410 cursor expired.The three designs side by side, in one picture:
Play the three options. Switch between them with the tabs at the top of the figure.
/nodes/N-7Laptop → API gateway → Metadata serviceDELETE nodes N-7 and its revisionsMetadata service → Metadata DBN-7deleteSwipe to see all columns
| DD4 side by side | |||
|---|---|---|---|
| Bad: delete the row | Good: tombstone, trimmed feed | Great: cursor can expire | |
| How an online device learns of the delete | Only by comparing listings | Feed event 43 | Feed event 43 |
| Undo | None | 30 days | 30 days |
Check it against the scenario
| The delete of plan.docx | |
|---|---|
| Situation | Outcome with the Great option |
| The phone was offline for 3 days | Its cursor is inside the feed. It reads event 43 and removes its copy |
| Alice restores the file on day 10 | deleted_at is cleared. A restore event brings the file back on every device |
| The tablet returns on day 50, with the file untouched | 410, a full listing, and the local copy is removed |
| The tablet had edited the file while it was off | That is the user's work. It is uploaded and comes back as a new file |
The trade-off to name. Deleted files cost storage for 30 days, and the feed has to be kept as long. A device that was away longer pays with a full resync: a listing of the whole drive in place of a few events. In exchange, a device that slept through a delete cannot undo it.
The feed grows by a billion rows a day, about 200 GB. A year of it is about 73 TB, more than twice all the other metadata, kept for devices that almost never return. A limit with an honest error is cheaper. And the full resync is correct however long the device slept.
"A delete is a change like any other: one transaction sets deleted_at on the node and appends a delete event to the feed. Online devices read the event and remove their copy. The row stays as a tombstone for 30 days so the file can be restored, and the feed is kept as long. A device with an older cursor gets 410 cursor expired, never a partial answer. It then fetches the full listing at a known change number, removes local files that are not in it and were not changed locally, uploads the ones that were, and continues from that number."
Follow-up: "During the resync the device finds a file that the server does not have. Delete it or upload it?" — If the file is exactly what the device last synced, the server deleted it: remove it. If it changed since then, or was never synced, it is the user's work: upload it.
| If the interviewer keeps going | |
|---|---|
| Question | Short answer |
| When are the bytes of a deleted file freed? | When no revision lists a chunk any more, its count is 0, and a day later the cleanup deletes it: DD3 of the S3-like Object Storage page. Each decrement is applied once per revision and chunk, because a count that drops twice frees bytes too early |
| A download stops at 60%. What then? | The download named a revision, and the manifest maps byte ranges to chunks. The device fetches the chunks it does not have yet. A newer revision that arrived in the meantime does not disturb it |
| 50 billion files in one PostgreSQL? | No. Split by user_id: a personal drive never touches another user, so every transaction stays on one shard. The chunks table is shared by all users and gets its own cluster, split by hash |
A push can be lost, merged or late. Use it as a hint, and let every device read the feed from its own cursor.
Two commits can share a time, and a slow transaction can commit with an old one. Number the changes per user inside the commit.
A crash in between skips those changes for ever. Apply first, save the cursor last, and make every event safe to apply twice.
The earlier edit disappears on every device without a sign. Check the base of every commit.
Each app version invents its own rule, and devices disagree. The server creates the conflict copy, once, in the commit transaction.
Every device shows a file with no content, and a dead upload leaves it there. The node, the revision and the feed event are written together.
A count of 0 is also what a slow upload looks like while it is still running. Unfinished parts belong to a session and go when it expires.
The device misses a delete and uploads the file again. Say "cursor expired" and make the device compare everything.
The shape of a strong answer: a small metadata store that must be exact, a blob store that must be cheap, and a change feed per user that every device follows from its own cursor. Three habits carry it.
Let the commit decide what exists
Parts are uploaded before the commit and belong to a session until it happens. The commit writes the node, the revision, the counts and the feed event together, so a device never reads about something that is not true.
The feed is the truth, a push is a hint
Changes are numbered per user inside the commit. A device asks for everything after its cursor, applies it, and then saves the new cursor. A lost push costs seconds.
Never lose bytes silently
A commit names its base, and a stale one becomes a conflict copy. A delete keeps a tombstone for 30 days. A cursor older than the feed gets 410 and a full resync.
| What the interviewer expects at each level | |
|---|---|
| Level | A strong answer shows |
| Junior | A metadata layer and a storage layer. Upload and download at a high level. Why a file is not one blob: chunks, a manifest, and a commit |
| Mid-level | Separates the upload session from the commit. Explains how chunk hashes give dedup and resume. Walks the feed: cursor, order, applying twice safely. Knows the conflict copy for two offline edits |
| Senior | States the commit as the one point where a change becomes visible. Tells the feed, the expired cursor and the conflict copy as one story. Separates cleanup by session expiry from cleanup by counts. Names limits such as a device far behind, and stays out of co-editing and multi-region merges |
These aren't toy problems — they reflect real infrastructure challenges at companies that keep millions of devices in sync. If you want to walk through this design in a mock interview or get feedback on your own approach, book a session with us. We're here to help you sharpen your thinking, build your confidence, and land your next offer.
Pick an answer for each question, and you see at once whether it is right. Show explanation opens the answer, why it is right, and why each of the other options fails.
Question 1 of 10
The laptop has sent all three chunks of plan.docx to the blob store, but not the commit. What does the phone see in /Work?
Question 2 of 10
A 500 MB upload stops after 119 of its 125 parts. What does the phone send when it is online again?
Question 3 of 10
An upload stops at part 119 and the user never comes back. What removes the 119 parts?
Question 4 of 10
The phone was in a tunnel and three pushes were lost. How does it get the three changes?
Question 5 of 10
Why is change_seq a counter per user and not the time of the commit?
Question 6 of 10
The phone applies event 42, crashes before it saves its cursor, restarts and receives event 42 again. What is the result?
Question 7 of 10
The laptop and the phone both edited revision 1 offline. The laptop commits first. What does the server do with the phone's commit, which names base_rev 1?
Question 8 of 10
Alice changes 2 MB at the end of a 10 MB file. How much does the laptop upload, and how much does the phone download?
Question 9 of 10
A tablet returns after 50 days and asks for the changes since cursor 40. The feed is kept for 30 days. What does the server answer?
Question 10 of 10
During the full resync the tablet finds plan.docx on its disk but not in the server's listing. The file is exactly what the tablet last synced. What does the tablet do?
| DD3 | A 500 MB upload drops at 95%. What happens next, and what if the user never comes back? | Upload in chunks and resume | Nobody owns the chunks of an upload that never finishes. Cleanup has to guess |
| DD4 | A file is deleted on the laptop. A tablet that was off for 50 days still has it. What happens when it wakes up? | The server deletes the row, and the tablet syncs | The tablet sees a file the server does not know, and uploads it again |
| Push for speed, the feed for correctness (DD1) |
| Large files on a bad network? | An upload resumes. It never starts again from byte 0 | An upload is a session with parts, not one request (DD3) |
| Is identical content stored once? | Yes, block by block. 200 PB of files take 60 PB | Chunks are named by their hash and counted. Cleanup must be safe |
| Can a deleted file come back? | Yes, for 30 days | A delete hides the file first. The bytes go later (DD4) |
| A push was sent | The device knows | Pushes are lost, merged and delayed. Only the device knows what it has applied |
| This save arrived last | It should win | It may be based on a version that is no longer the current one |
| The file is deleted | Its bytes can go | The user may restore it, and another file may share its chunks |
| The device asks for changes since 40 | The server still has them | The feed is kept for 30 days. Past that, the honest answer is an error |
| Changes |
| 100 per active user a day: 1 billion a day, about 12,000 a second, 20,000 at peak |
| Feed reads, if every device polls every 5 minutes | 30 million / 300 s = 100,000 a second |
| Metadata | About 30 TB: folders and versions, chunk rows, and 30 days of feed |
| One commit transaction: revision, counts and feed event | A device can never read about a change that is not true yet |
| Every commit names the revision it started from | A stale save is noticed, not applied (DD2) |
| A change number per user, raised inside the commit | One total order with no gaps and no ties |
| Push is a hint. The feed and the cursor are the truth | A lost push costs seconds, never a change (DD1) |
| Tombstones and a feed kept for 30 days, then an explicit error | A delete reaches every device or forces a full resync (DD4) |
parent_idnameSTRING |
| Unique together among live nodes. /Work/plan.docx is the name plan.docx under the folder N-3 |
is_dir | BOOL | Folder or file |
head_rev | INT | The current revision of a file. A commit must name it as its base (DD2) |
deleted_at | TIMESTAMP | Empty for a live node. Set, the row is a tombstone (DD4) |
| The chunk hashes in order, for example b7e1, 4d90, c35a. Never changes |
size, device_id, created_at | INT, STRING, TIMESTAMP | Bytes, which device saved it, and when |
INT |
| How many revisions list this chunk. Changed only inside a commit or a purge |
parts | LIST | For each part: its index, its hash, and whether it has arrived |
state | ENUM | CREATED / UPLOADING / COMMITTING / COMMITTED / ABORTED / EXPIRED (DD3) |
expires_at | TIMESTAMP | 7 days after the session was opened |
upsert / delete / restore |
node_id, rev_no | STRING, INT | Which node changed, and which revision is current now |
payload | JSON | Parent, name and size: enough for a device to apply the change |
| The name goes into conflict copies. The token is for hints |
base_rev| 200. A rename or a move is one row and one feed event |
DELETE /nodes/{id} | base_rev | 204. The node becomes a tombstone |
POST /nodes/{id}/restore | No body | 200, for 30 days after the delete |
GET /nodes/{id}/revisions/{rev}/content | Optionally a byte range | 200: the manifest and presigned GET URLs |
3. POST /upload_sessions/S-1/commitbase_rev: the revision this save started from |
committed with the new revision, or conflict_copy with a new node (DD2) |
GET /upload_sessions/S-1 | No body | The state and the parts that are still missing, with fresh URLs |
DELETE /upload_sessions/S-1 | No body | 204. The session is ABORTED |
POST /devices | A device name and a push token | 201. The device will get hints |
| Phase 3: Edit (FR2, FR5) |
| Green |
| Alice changes the last pages on the laptop |
| Revision 2, one new chunk of 2 MB, feed event 42 |
| Phase 4: Delete (FR1) | Purple | Alice deletes the file. 30 days later it is purged | Nothing |
| 3 | The laptop gets S-1 and one presigned PUT URL per chunk, valid 15 minutes. | Nothing |
| 4 | The laptop sends each chunk straight to the blob store. The blob store hashes what it receives and refuses a mismatch. | Three chunks in the blob store |
| 5 | The blob store reports the stored chunks. The folder still shows nothing. | S-1: UPLOADING, parts 3 of 3. chunks rows b7e1, 4d90, c35a with count 0 |
| 6 | The laptop sends POST /upload_sessions/S-1/commit. One transaction does the rest. Only now does the file exist. | Node N-7, revision 1 with its manifest, counts 0 to 1, last_seq 40 to 41, feed event 41, S-1 COMMITTED |
next_cursor| Nothing |
| 4 | The phone sends GET /nodes/N-7/revisions/1/content. It gets the manifest and presigned GET URLs. | Nothing |
| 5 | The phone fetches the three chunks straight from the blob store, in parallel. It checks each hash, joins the chunks and writes the file. | The file on the phone |
| 6 | Only now the phone saves its new cursor. | Phone: cursor 40 to 41 |
The laptop gets S-2, two chunks marked stored, and one presigned PUT URL. |
| Nothing |
| 4 | The laptop sends chunk e2f8, 2 MB, to the blob store. The blob store reports it. | chunks row e2f8 with count 0. S-2: parts 3 of 3 |
| 5 | The laptop commits S-2 with base_rev 1. The metadata service locks node N-7. Its head is 1, so the base matches. | Revision 2, head_rev 1 to 2, counts b7e1 and 4d90 1 to 2, e2f8 0 to 1, last_seq 41 to 42, feed event 42 |
| 6 | The phone gets a hint and reads the feed from cursor 41: event 42. It compares the new manifest with the chunks it has and downloads only e2f8. | Phone: the file at revision 2, cursor 42 |
| 3 | The phone gets a hint and reads the feed from cursor 42: event 43. It removes its copy. | Phone: file removed, cursor 43 |
| 4 | 30 days later the cleanup worker selects the nodes whose deleted_at is older than 30 days. | Nothing |
| 5 | One transaction removes the node and its two revisions, and lowers the counts. | N-7 and revisions 1 and 2 deleted. Counts b7e1 and 4d90 2 to 0, c35a and e2f8 1 to 0 |
| 6 | A day later the four chunks still have count 0. The cleanup worker deletes them from the blob store. | Chunks and their rows removed |
| DD1 |
| Tell every device what changed |
| The phone is in a tunnel while three changes are committed |
| NFR1, NFR3 — Consistency, scale |
| DD2 | Two devices save the same file | Laptop and phone both edit revision 1 offline | NFR5 — Nothing lost silently |
| DD3 | A 500 MB upload on a bad network | The connection drops at 95%, or the user never returns | NFR4, NFR5 — Cost, nothing lost |
| DD4 | A delete must reach every device | A tablet returns 50 days after a delete | NFR1, NFR5 — Consistency, nothing lost |
| A lost push means |
| A lost change |
| There are no pushes |
| A short delay |
| Feed requests from 30 million devices | None | 100,000 a second | About 33,000 a second, as a safety net |
conflict_copyplan.docx with the laptop's edit and the copy with the phone's edit.| Who decides what a conflict looks like |
| Nobody. It is not noticed |
| Each app version |
| The server, in one place |
| What every device shows | One file, the phone's | It depends on the app | The same two files |
COMMITTINGCOMMITTEDEXPIRED on day 7. A commit is refused from then on.Two kinds of cleanup, never mixed. Chunks of a committed revision are freed by reference counts. Parts of an unfinished upload are freed when their session expires. They were never visible, so the only question is whether the upload is still alive, and the session answers it.
| Leaves nothing behind |
| 476 MB that nobody can safely delete |
| Its parts are removed on day 8 |
| A slow upload that is still running | Starts over at every drop | Can lose chunks to the cleanup | Safe while its session is open |
| Its count is above 0. The cleanup leaves it alone |
| The phone tries to commit on day 9 | Refused: the session is EXPIRED. The upload starts over in a new session |
GET /sync/snapshotplan.docxThe tablet can tell the two cases apart because it keeps, for each file, the revision and the hashes it last synced.
| The tablet on day 50 |
| Uploads the file again |
| Reads a feed with a hole, uploads the file again |
| Gets 410, resyncs, removes its copy |
| What the server says about the missing events | Nothing | Nothing | 410 cursor expired |
| Why 4 MB chunks? |
| Smaller chunks mean more rows and more requests: 500 MB in 64 KB chunks is 8,000 of them. Larger chunks mean an edit uploads more and dedup finds less. A few MB is the usual middle |
| A disk returns wrong bytes without an error? | Scrubbing. A background job reads chunks again and hashes them. A chunk whose hash is not its name is replaced from another copy |
| A tiny file. Is a session too much? | A single call can open the session, carry the bytes and commit. It is a shortcut for the client, not a second path: the same base check and the same feed event apply |