LESSON 05 · Versions and conflicts

Preserve competing edits

Compare the expected base revision so a later edit cannot silently erase another.

SYSTEM VIEW

The file path

Diagram view
Current—
Edits kept—

Watch a phone and a laptop edit revision 12 offline, see what becomes of each edit, then replay it two other ways.

  1. The Phone and the Laptop both sync a file at revision 12, the current revision in Metadata DB. Then both go offline, so neither sees what the other does next.

    Both start from
    rev 12

    What changed

    • Phone has rev 12
    • Laptop has rev 12
    • Both offline
  2. Offline, each device edits its own copy of revision 12. When it reconnects, its upload will declare the revision its edit started from, base 12, so Metadata DB can tell whether the file has changed since.

    Each upload declares
    its base revision
    Both bases
    rev 12

    What changed

    • Phone’s edit on rev 12
    • Laptop’s edit on rev 12
  3. The Phone reconnects first and commits with base 12. Metadata DB compares that base with the current revision, a check called compare-and-set. 12 matches 12, so the Phone’s edit publishes as revision 13, a new immutable version.

    Base = current
    12 = 12
    Publishes
    rev 13, immutable

    What changed

    • Phone back online
    • Rev 13 published
  4. The Laptop reconnects and commits with base 12, but the current revision is now 13, so the check fails. Its bytes are kept as a conflicted copy beside 13. The user compares, merges where the format allows, or chooses: the cost falls on people.

    Base ≠ current
    12 ≠ 13
    In Dropbox
    a “conflicted copy” file

    What changed

    • Laptop back online
    • Conflicted copy beside rev 13
  5. Replay it with silent last-writer-wins, where the latest upload replaces the rest with no base check. The Phone publishes revision 13, then the Laptop’s upload overwrites it, and the Phone’s edit is gone. It can be acceptable for data that is cheap to regenerate, such as cached thumbnails.

    Base check
    none
    Can be fine for
    cached thumbnails

    What changed

    • No base check
    • Laptop’s upload replaces rev 13
    • Phone’s edit
  6. Deletions can conflict too. Replay from revision 13: the Laptop goes offline, then the Phone deletes the file. Metadata DB doesn’t forget the file: it keeps a tombstone under the file’s stable ID, a record that the file was deleted.

    Tombstone
    says it was deleted
    Kept under
    the file’s stable ID

    What changed

    • Laptop offline with rev 13
    • File deleted
    • Tombstone
  7. The Laptop reconnects holding revision 13. Metadata DB finds the tombstone and answers that the file was deleted, so the Laptop removes its local copy. Without a tombstone, that copy would look like a file the server has never seen, and syncing would bring the file back.

    With a tombstone
    copy removed
    Without one
    the file comes back

    What changed

    • Laptop back online
    • Laptop’s local copy removed

Space plays · ← → step · Home resets

THE IDEA

How it works

Each upload declares the revision it was based on. At commit, compare that base with the current revision, a check known as compare-and-set. A match publishes a new immutable version; a mismatch preserves the submitted bytes as a conflict copy or draft. The user may compare, merge when the file format permits it, or choose a version. Silent last-writer-wins, where the most recent upload replaces the rest, can destroy work.

Walk through it. A phone and a laptop both start from revision 12 while offline. The phone reconnects first: its base 12 matches, so it publishes 13. The laptop then submits base 12, which no longer matches, so its bytes become a separate copy beside 13. Dropbox does this with its “conflicted copy” files. The cost falls on people: copies pile up and someone must reconcile them. Last-writer-wins can be acceptable for data that is cheap to regenerate, such as cached thumbnails.

Retain revisions according to an explicit policy. Delta sync transfers changed blocks, but each manifest still needs enough references to reconstruct its revision. Shared blocks keep history cheap: ten revisions of a 100-block file, each changing one block, occupy 109 blocks rather than 1,000. Renames, moves, and deletions can also conflict. Stable IDs and deletion tombstones, records saying a file was deleted, prevent an offline copy from accidentally resurrecting a removed file. File sync is not a collaborative text protocol.

DECISION POINT

A phone and laptop both edit revision 12 offline. The phone publishes 13 first. What happens to the laptop edit?

Write a sentence or two to unlock the guidance. Committing first is what makes it stick.

Keep in mind

  • Compare base revision at commit.
  • Keep both contents when automatic merge is unsafe.
CHECK YOUR UNDERSTANDING

Put it into practice.

1 OF 2
RecallQUESTION 01

What must a new revision declare to detect a stale edit?

Choose an answer. You’ll see the explanation once you get it right.

Next lesson

0 of 2 checkpoints answered correctly to complete this lesson.