In a cloud-drive service, one device deletes a folder while an offline laptop edits a file inside it; what should the server do when the laptop syncs?
answer
- no conflicted copy of nothing
- the side that saw less loses
- minimal path, not whole folder
- deleted state must outlive offline gaps
- identify files by stable ID
basics
~20 sPreserve the edit: restore the edited file, recreating its parent path, rather than dropping it, because losing work is worse than an unexpected file reappearing. Record the restore in the journal so every device sees it.
solid answer
~50 sThe folder delete committed first and left deleted-state records (tombstones) for the folder and its children. The laptop then uploads an edit whose base is `r5`, but the file's current state is deleted at `r6`, so the base-revision check fails: this is an **edit-versus-delete conflict**. Letting the delete win drops real work silently. The usual policy is **edit wins for the edited item**: recreate the minimal parent path, commit the file as a new revision there, leave the folder's other, untouched files deleted, and append journal entries so the deleting device sees the file return. The reverse direction matters too: an offline device that deletes a file based on `r5` when the server holds `r6` is deleting a version it never saw, so the server should keep `r6` rather than apply the stale delete. Tombstones must be kept at least as long as the cursor retention window, or the server cannot tell a stale edit from a new file.
go deeper
Remember the principle: when a delete and an edit collide, keep the edited content rather than dropping it.
Explain how tombstones plus the base-revision check detect the conflict in both directions, and why an unknown file ID alone is ambiguous.
Show the resurrection steps, why only the minimal path is restored, how tombstone retention ties to the journal window, and how stable IDs tame move cases.
Weigh safety against user surprise: trash and version history make policies recoverable, and explaining resurrected files in the product is part of the design.
## Why deletes deserve their own rule Concurrent edits to the same file have an obvious safe outcome: keep both versions. A delete is different, because one side wants the item to exist and the other wants it gone. There is no conflicted copy of nothing. A cloud-drive service needs an explicit policy for **edit-versus-delete**, and the policy should follow one principle: **never silently lose user content**. ## Detecting it When a folder is deleted, the server does not simply erase rows. It records a **deleted state** (a tombstone) for the folder and each child, with a new revision, and appends journal entries. Later, the offline laptop uploads an edit to `plan.txt` whose base is `r5`. The server checks the current state: the file is marked deleted at `r6`. The base does not match, so the same compare-and-set that catches edit-versus-edit catches this too. Without the tombstone, the server would see an upload for an unknown file ID and could not tell whether it was new or stale. ## The two directions | Situation | Stale side | Safe outcome | |---|---|---| | Folder deleted, offline edit to a child arrives later | The edit | Restore the edited file and its parent path; keep other children deleted | | File edited to r6, offline delete based on r5 arrives later | The delete | Keep r6; the delete targeted a version its author never saw | | File deleted, offline delete of the same file arrives | Neither | No-op; both wanted the same outcome | In both conflicting rows the side that saw less loses its **destructive** effect, while all content survives. ## Restoring the edited file The typical resurrection steps: 1. Detect that the base revision points at a live file that is now deleted. 2. Recreate each missing ancestor folder on the path, as new revisions, so the file has somewhere to live. 3. Commit the uploaded content as the file's next revision. 4. Append journal entries for the recreated folders and the file. 5. Leave every other child of the original folder deleted. Step 5 is a deliberate choice. Restoring the whole folder with thousands of files would override a clear user action because of one edit. Restoring just the minimal path respects both intents: the user wanted the folder gone, and someone also produced new work inside it. Some designs instead place the edited file somewhere visible, such as a recovered-items location, when recreating the old path would be confusing. The essential property is the same: the edit is kept and every device learns about it. ## Tombstones and retention - A tombstone must live at least as long as a device may stay offline and still sync incrementally, meaning the change-journal retention window. - After the window, a returning device must do a full resync; its reconciliation rules then decide what to do with local files that the server no longer lists. - Many services also keep deleted files in a **trash** with version history for a period, which makes a wrong policy decision recoverable by the user. The general theory of tombstones in replicated stores is its own topic; for file sync, the practical need is that deleted state outlives the longest incremental-sync gap. ## Moves make it harder If one device moves a folder while another deletes it, or edits a file inside a folder that was moved, identifying files by stable ID rather than path keeps these cases manageable: an edit to file ID `f_91` applies wherever that file now lives. Path-keyed designs turn ordinary moves into apparent deletes and multiply these conflicts. ## Telling the user A restored file appearing in a folder the user deleted can be confusing. Good clients surface it: a notification or activity-feed entry that the file was kept because it was edited on another device. The system stays safe, and the surprise is explained.
- Why not restore the entire deleted folder when one of its files was edited?The delete was a deliberate user action on the whole folder. Restoring thousands of untouched files because of a single edit would override that intent and surprise the user. Recreating only the path needed for the edited file keeps the new work and still honors the delete for everything nobody touched.
- How long must the server remember that a file was deleted?At least as long as a device can be offline and still sync incrementally, which is the change-journal retention window. Within that window the tombstone lets the server recognise a stale edit or delete. Beyond it, the device must do a full resync, where reconciliation rules rather than tombstones decide what happens to local files.
saying these in an interview costs you the question
- Deletes should always win because they were a deliberate action
- A deleted folder's rows can be purged from metadata immediately
- A delete based on an old revision should remove the current one
- Keeping one edited file means restoring the entire deleted folder
- Edit-versus-delete cannot happen if devices sync every minute