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
- Split each file into blocks and fingerprint each block (a content hash).
- On a change, upload only blocks the server doesn’t already have.
- Store the file’s list of blocks as a new version in a database, checking it was based on the latest version.
- Tell the user’s other devices something changed; they download only the blocks they lack.
- 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
- How to size a sync service: storage, replicas, dedup, edit traffic and open connections.
- How block-level delta sync works, and why content-defined chunking survives insertions that break fixed blocks.
- How a base-version check turns concurrent offline edits into conflict copies, and how to defend the design.
Sections
- Requirements and numbers
- API and data
- Architecture
- Deep dive: delta sync
- Deep dive: conflicts
- Design review
Cheat sheet
| File version | ordered list of block hashes |
|---|---|
| Upload | missing blocks first, then commit |
| Insertions | content-defined chunking |
| Concurrent edits | base-version check → conflict copy |
| Notify | "changed" push, pull by cursor |
The interactive simulations and the scored design review load with JavaScript.