Designbench

Lesson 6.9 · 25 min

File sync

Edit a real 2 MB file in memory and watch a 10-byte insertion force fixed blocks to re-send everything while content-defined chunks send 21 KB, then reconnect two offline devices without losing an edit.

The idea in plain words

File sync keeps the same files on all your devices: edit on your laptop and it shows up on your phone. To be fast it sends only the parts that changed, and when two devices edit the same file offline it must never silently lose one of the edits.

The problem it solves

Files change on one device and must appear on the others quickly, without re-uploading huge files for small edits and without losing work when two devices edit the same file.

How it works

  1. Split each file into blocks and fingerprint each block (a content hash).
  2. On a change, upload only blocks the server doesn’t already have.
  3. Store the file’s list of blocks as a new version in a database, checking it was based on the latest version.
  4. Tell the user’s other devices something changed; they download only the blocks they lack.
  5. If two devices changed the same version, keep both: save the second as a conflict copy.

Example

You edit one slide in a 200 MB presentation. Only the 2 blocks holding that slide (8 MB) are uploaded, not 200 MB. Your phone downloads those 2 blocks and rebuilds the file.

Key terms

Block (chunk)
A piece of a file; files are stored and sent as blocks.
Content hash
A fingerprint of a block’s bytes; identical blocks have the same hash.
Delta sync
Uploading only the blocks that changed.
Deduplication
Storing each unique block once, even if many files contain it.
Conflict copy
A second version saved when two devices changed the same file, instead of overwriting one.

In this lesson you'll learn

Sections

  1. Requirements and numbers
  2. API and data
  3. Architecture
  4. Deep dive: delta sync
  5. Deep dive: conflicts
  6. Design review

Cheat sheet

File versionordered list of block hashes
Uploadmissing blocks first, then commit
Insertionscontent-defined chunking
Concurrent editsbase-version check → conflict copy
Notify"changed" push, pull by cursor

The interactive simulations and the scored design review load with JavaScript.