Case study demo

File sync (Google Drive)

Upload, chunk and sync files across devices, and resolve edit conflicts.

An interactive demo of how this system behaves. It runs in your browser.

Case study · Live model

How file sync behaves

One 64 MB file lives on a laptop, a phone and in the cloud. The sync app cuts it into 16 blocks. The cloud keeps the blocks in a block store, and the list of blocks for each file in a metadata service. Edit the file, copy it, or edit it on two devices at once, and watch what is sent.

Try it

Lab time 3.0 s
listsblocksLaptop, in stepLaptopin stephas version 1Metadata service, report.bin: version 1Metadata servicereport.bin: version 11 file listedBlock store, 16 blocksBlock store16 blocks64 MBPhone, in stepPhonein stephas version 1
  • Laptop — in step — healthy — has version 1
  • Metadata service — report.bin: version 1 — healthy — 1 file listed
  • Block store — 16 blocks — healthy — 64 MB
  • Phone — in step — healthy — has version 1
  • Ask which blocks the cloud lacks
  • Send a block, or a new list of blocks
  • Ask for the newest list
  • Fetch a block
Sent to the cloud
0 MB
whole files would be 0 MB
Saved: unchanged
0 MB
blocks not sent because they did not change
Saved: already there
0 MB
blocks not sent because the cloud had them
Blocks in the store
16
64 MB for 1 file
Edits that clashed
0
0 kept as a second file
Edits replaced
0
gone, and nobody was told

Numbers add up:0 finished syncs: 0 MB of whole files = 0 MB sent + 0 MB unchanged + 0 MB already in the cloudThe lab checks this sum as it runs, so a counting mistake would show here.

Controls

Edits
every 4 s
The phone
Phone

An offline phone keeps its edits and sends them when it is back.

How it syncs

Off: the app offers all 16 blocks of the file each time. Only "Skip blocks the cloud has" can then save any.

Before it sends, the app asks which blocks the cloud does not have yet. It names each block by a fingerprint: a short number worked out from its content.

Off: the edit that reaches the cloud last replaces the other one.

The file, block by block

WhereStateVersionTimes each of the 16 blocks was edited
Laptopin step10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Cloudwritten by the laptop10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
Phonein step10 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Two rows with the same numbers hold the same file. A device's version is the cloud version its file was made from.

Files in the cloud

FileVersionLast written bySize
report.bin1Laptop64 MB
Megabytes sent to the cloud, against sending whole files
Whole filesSent
00.30.50.811s2s3s
Show data table
TimeWhole filesSent
1s00
1s00
2s00
2s00
3s00
3s00

What just happened

Nothing yet. Start traffic or run an experiment.

What this model simplifies
  • Every block is 4 MB, and an edit changes one whole block. In a real file, one new line near the start can shift every later block. So some sync and backup tools choose where to cut by looking at the content. This is called content-defined chunking.
  • Sending one block takes 0.5 s and fetching one takes 0.25 s, one block at a time. Real apps send several at once and squeeze them first.
  • A fingerprint here is a plain number and takes no time to make. A real one is a hash such as SHA-256, and the app must read every byte of the block to work it out.
  • The other device is told about each change at once. Real apps keep a connection open to be told, and fall back to asking every few minutes.
  • A clash is found for the whole file, even when the two edits changed different blocks. Real apps do the same for most files, because joining two edits is safe only for some kinds of file.
  • Old versions cannot be opened here, though their blocks stay in the store. Real services keep old versions for weeks, which is how a replaced edit can sometimes be found again.