💬
✉️
📸
▶️

Loading…

Design Dropbox: file chunking, sync, and storage

DropboxGuided Mode

Sync Service: Propagate Changes Across Devices

Uploading is only half the problem. The other half: how does Device B know a file changed on Device A? The Sync Service maintains a per-user event log. Every file change emits an event. Devices poll or long-poll for events since their last cursor.

Request Flow

1

File change emits sync event

After the Metadata Service records the update, it publishes a change event to the Sync Service. The event contains: user_id, file_id, version, operation (create/update/delete).

{
  "cursor": 47382,
  "changes": [{
    "path": "/Notes/todo.txt",
    "rev": "v12",
    "op": "update"
  }]
}
2

Device B receives notification

Device B holds a long-poll connection to the Sync Service. When the change event arrives, the server responds. Device B downloads only the changed chunks from S3 — not the full file.

3

Conflict resolution

If both devices edited the same file offline, the Sync Service detects diverging version vectors. It applies last-write-wins (by timestamp) as the canonical version and renames the loser to 'file (conflicted copy).docx'.

Why We Need This

Without a sync service, every device would need to poll all metadata every few seconds. At 700M users × every 5 seconds = 140M requests/second just to check for changes. Event-based sync via cursor means each device only fetches its own delta.

Key Insight

The sync cursor is a bookmark into the event log. A device reconnecting after a week offline sends its last cursor. The server replays only events since that cursor — O(changes) not O(all files).

Step 5 of 8