Skip to content
SD-5 · Back to the write-up

Design a File Sync and Storage

Upload only the blocks the server lacks, commit with a version check into a per-folder journal, and push a short notice so other devices fetch from their cursor.

Follow a request

Devices
Edge
Services
Data
Sync clientLaptop or phone
NotificationWebSockets
Load balancerAPI calls
Metadata serversCommits, changes
Block serversBytes
Change busns events
Cleanup jobsVersions, blocks
Metadata DB32 shards by ns
Block indexhash → location
Block storageErasure coded
1client → lb · POST /blocks/checkAna changes one slide in a 100 MB deck. Her client hashes the 25 blocks and asks which of the 3 that changed the server lacks.1 / 15

The numbers, at a glance

An average change……sends 1/20 of the file
100 KB of new blocks2 MB whole file
Block storage grows225 TB of new blocks a day after dedup
Why not poll10 million polls a second at 300 million devices
So devices hold an idle connection and are told when something changes.

An edit reaches another device

Blocks first, commit second, notice third. The notice carries no data.

Laptop
Block server
Metadata server
Metadata DB
Notification
Desktop
1 PUT missing block
2 201
3 commit, parent rev 41
4 append if rev = 41
5 seq 9,812
6 200 rev 9,812
7 ns 77 changed
8 changed: ns 77
9 changes after cursor
10 22 entries
11 GET block h7
12 4 MB
RequestResponseAsync, does not block

What travels when a file changes

The decision that sets every byte rate in this design.

Whole files
Too heavy
edit 1 slide
PUT 100 MB
100 MB to each device
+ Simple.− 200 GB/s at peak; a full copy per version.
Blocks by hash
Our pick
hash 25 blocks
check → 1 missing
PUT 4 MB, commit list
+ Only new blocks travel; dedup for free.− Insertions shift later blocks.
Content-defined chunks
For some types
rolling hash
cut at content marks
PUT changed chunks
+ Insertions stay local.− Variable sizes, more CPU.

How it grows

Add a box only when a number forces you to. Highlighted boxes are new at each stage.

Stage 1 · ≈ 100,000 devicesMake it work
Sync client
App server
DatabaseObject storage
One server, whole files, polling every 30 seconds.
Stage 2 · ≈ 1 million devicesSync blocks
Sync client
Load balancer
Metadata serversBlock servers
Journal DBBlock indexBlock storage
Only changed blocks travel; commits carry a version check.
Stage 3 · ≈ 10 million devicesPush changes
Sync client
Notification serversLoad balancer
Metadata serversChange busBlock servers
Journal DBBlock indexBlock storage
333,000 polls a second: push a notice instead.
Stage 4 · ≈ 300 million devicesShard and clean up
Sync client
Notification serversLoad balancer
Metadata serversChange busBlock serversCleanup jobs
32 journal shardsBlock indexBlock storage
500,000 ops a second and 125 TB: 32 shards by namespace, plus cleanup.
Was this walkthrough useful?Your vote tells us what to improve next.