File Sync system design: how it works

Splits files into blocks named by their content, uploads only blocks the server lacks, and tells your other devices what changed.

Loading the interactive diagram…

How File Sync works, step by step

Splits files into blocks named by their content, uploads only blocks the server lacks, and tells your other devices what changed.

Your devices

Your laptop
Client · Hypothetical. Where you just saved a change to a 40 MB report.
Your phone
Client · Hypothetical. Another device signed in to the same account, waiting to hear about changes.

Front door

API gateway
Gateway · Hypothetical. Checks who you are and sends file-list requests and block transfers to the right service.

Services

Block service
Service · Hypothetical. Stores and serves blocks by their hash. Knows nothing about files or folders.
Metadata service
Service · Hypothetical. Knows the folder tree: which files exist, each file's versions, and which blocks make up each version.
Notification service
Service · Hypothetical. Holds each device's waiting request and answers it when its account changes.

Data

Block storage
Database · Hypothetical. Every block, once, keyed by its hash. Petabytes, cheaply.
Metadata database
Database · Hypothetical. Files, versions, block lists and the change log. Small compared with the blocks, but read constantly.

Flow: Save a change on your laptop

The laptop says which blocks the new version uses; only the one the server lacks is uploaded, then the new version is saved and other devices are told.

  1. Your laptop → API gateway (report.pdf = h1 h2 h3…). You save a one-line edit to a 40 MB report. The app splits it into 10 blocks and hashes them; only the third block's hash changed.
  2. API gateway → Metadata service (Commit v7 from v6). It asks to save version 7 of the file, built on version 6, listing all 10 block hashes.
  3. Metadata service → Metadata database (Which blocks are new?). The metadata service checks which of those blocks already exist.
  4. Metadata database → Metadata service (Only h3 is new). Nine of the ten blocks are already stored.
  5. Metadata service → API gateway (Upload h3 first). So the commit waits for one block.
  6. API gateway → Your laptop (Need h3). The laptop learns it only has to send 4 MB, not 40.
  7. Your laptop → API gateway (Upload h3 (4 MB)). It uploads the one changed block.
  8. API gateway → Block service (Store h3). The gateway passes it to the block service, which checks the content matches the hash.
  9. Block service → Block storage (Put 9f2c…). The block is stored under its hash.
  10. Block storage → Block service (Stored). Safe, in more than one data centre.
  11. Block service → API gateway (Have h3). The block service confirms.
  12. API gateway → Your laptop (Got h3). The laptop can now finish the commit.
  13. Your laptop → API gateway (Commit v7 from v6). It asks again to save version 7.
  14. API gateway → Metadata service (Commit v7 from v6). The gateway passes it on.
  15. Metadata service → Metadata database (Save v7, cursor 89). Every block exists now, so version 7 is saved and the account's change cursor moves to 89.
  16. Metadata database → Metadata service (Saved). Version 7 is the latest.
  17. Metadata service → Notification service (Account changed). The notification service is told, so waiting devices can be woken.
  18. Metadata service → API gateway (Committed v7). The laptop is answered.
  19. API gateway → Your laptop (Synced ✓). The file shows a green tick.

Flow: Your phone catches up

The phone's waiting request is answered, it asks what changed since its cursor, and downloads only the blocks it doesn't have.

  1. Your phone → Notification service (Waiting since cursor 88). The phone has been holding a request open, saying the last change it knows is cursor 88.
  2. Notification service → Your phone (Something changed). The account changed, so the waiting request is answered at once.
  3. Your phone → API gateway (Changes since 88?). The phone asks for the details.
  4. API gateway → Metadata service (Changes since 88). The gateway passes it to the metadata service.
  5. Metadata service → Metadata database (Log after cursor 88). It reads the change log.
  6. Metadata database → Metadata service (report.pdf v7). One change: report.pdf is now version 7, with its block list.
  7. Metadata service → API gateway (report.pdf v7: h1…h10). The phone gets the new block list and the new cursor, 89.
  8. API gateway → Your phone (v7 + cursor 89). The phone already has nine of the blocks from version 6.
  9. Your phone → API gateway (Download h3). So it downloads only h3.
  10. API gateway → Block service (Get h3). The gateway passes it to the block service.
  11. Block service → Block storage (Get 9f2c…). The block is read from storage.
  12. Block storage → Block service (4 MB). The block comes back.
  13. Block service → API gateway (h3). Sent on to the phone.
  14. API gateway → Your phone (h3 (4 MB)). The phone puts version 7 together from its blocks. It's in sync.

Flow: Two devices edit the same version

Both started from version 6. The first commit wins; the second is told the file moved on, and keeps its work as a conflicted copy.

  1. Your phone → API gateway (Commit v7 from v6). You edited the same file on the phone while offline, also starting from version 6. Its blocks are uploaded the same way as before.
  2. API gateway → Metadata service (Commit v7 from v6). The phone asks to save its version, built on version 6.
  3. Metadata service → Metadata database (Is v6 still latest?). Before saving, the metadata service checks the version it's built on is still the latest.
  4. Metadata database → Metadata service (No: latest is v7). The laptop's version 7 got there first.
  5. Metadata service → API gateway (Conflict: now v7). The commit is refused rather than silently overwriting the laptop's edit.
  6. API gateway → Your phone (Conflict). The phone saves its edit as "report (Phone's conflicted copy).pdf", a separate file, and downloads version 7. Nothing is lost; you choose what to keep.

Flow: Download one block

The block path on its own: the busiest request, since every device fetches blocks.

  1. Your phone → API gateway (Download h3). A device asks for a block by its hash.
  2. API gateway → Block service (Get h3). The gateway passes it to the block service.
  3. Block service → Block storage (Get 9f2c…). Read from storage.
  4. Block storage → Block service (4 MB). The block comes back.
  5. Block service → API gateway (h3). Sent on.
  6. API gateway → Your phone (h3 (4 MB)). The device has the block.

HowItScales is not affiliated with the companies shown. Components marked Assumption or Hypothetical are not confirmed by the company.