System design · Chunking, dedup, sync

How to design Dropbox or Google Drive

Split each file into hashed chunks, upload only the chunks the server lacks straight to object storage, keep file-to-chunk metadata in a sharded database, and tell other devices about changes through a notification channel. The hard parts are not re-sending what the server has, telling every device within seconds, and two people editing one file.

Updated · 5 min read

A teaching design of a system like Dropbox or Google Drive, not the real architecture of either company.

Missing blocks go straight to S3 on pre-signed URLs. The metadata service commits versions and journal entries, then publishes events that wake other devices on that namespace.

Dropbox architecture diagram

Missing blocks go straight to S3 on pre-signed URLs. The metadata service commits versions and journal entries, then publishes events that wake other devices on that namespace.

The short version

  • File bytes and metadata are separate problems. Bytes go straight to object storage; metadata lives in a database sharded by namespace.
  • Files are lists of content-hashed blocks, which gives you dedup, cheap versions and delta sync.
  • Each namespace has an ordered change journal. Devices keep a cursor per namespace; notifications are only a hint to read forward.
  • On a conflict keep both edits: the server's version stays, the loser becomes a conflicted copy.

Clarifying questions to ask first

  • What's in scope? (Assume upload, download, sync across devices, version history, sharing and offline edits. Leave out real-time co-editing, search and previews.)
  • How fast must a change reach other devices? (Assume within seconds.)
  • What scale? (Assume 100M daily users making about 10 saved changes each, and 500M accounts.)
  • What must never happen? (A saved file lost or silently corrupted, or one person's edit silently overwritten.)
  • How large are files? (Assume gigabytes, and a small edit must not re-upload the whole file.)

Numbers that shape the design

These are interview assumptions, stated out loud.

QuantityAssumptionResult
File changes100M daily users × 10 saved changes each1B a day ≈ 11,600/s average, ≈ 35,000/s at a 3× peak
Upload bandwidthabout 1 MB of new data per change≈ 1 PB a day ≈ 12 GB/s average, before dedup and delta sync
Stored data500M accounts × 2 GB used on average≈ 1 EB logical, before replicas and dedup
Sync connectionshalf of daily users have a device online at peak≈ 50M open long-poll or notification connections

Twelve gigabytes a second must not flow through application servers, and tens of millions of idle devices need a cheap way to wait.

API

POST /api/uploads
{ "path": "/docs/plan.pdf", "size": 9437184, "blocks": ["9f2c...", "a71e...", "c03b..."] }
→ 200 OK  { "upload_id": "up_81", "missing": [ { "hash": "c03b...", "url": "https://s3...presigned" } ] }

PUT https://s3...presigned            (raw block bytes, client to S3 directly)

POST /api/uploads/up_81/commit
{ "base_version": 6 }
→ 200 OK        { "file_id": "f_42", "version": 7 }
→ 409 Conflict  { "latest_version": 8 }

GET /api/changes?cursor=ns_9:1042
→ 200 OK  { "changes": [ ... ], "cursor": "ns_9:1057", "has_more": false }

GET /api/changes/wait?cursor=ns_9:1057&timeout=60
→ 200 OK  { "changed": true }

POST /api/shares  { "folder_id": "f_10", "user_id": "u_7", "role": "editor" }

The client hashes its blocks, asks which are missing and uploads only those. base_version lets the server detect a conflict instead of overwriting. The wait call returns only a flag; the client then fetches the changes.

Data model

Metadata lives in a relational store such as RDS PostgreSQL, sharded by namespace: a user's own root or a shared folder. Block bytes live in S3, keyed by hash.

files
  namespace_id    bigint     shard key
  file_id         bigint
  parent_id       bigint     folder
  name            text
  latest_version  int

file_versions
  file_id         bigint
  version         int
  block_hashes    text[]     ordered list, e.g. SHA-256 per block
  size            bigint

blocks
  hash            text       primary key, also the S3 object key
  size            int
  ref_count       int

journal
  namespace_id    bigint     partition key
  seq             bigint     increasing per namespace
  file_id         bigint
  version         int
  op              text       add, edit, move, delete

namespace_members
  namespace_id    bigint
  user_id         bigint
  role            text       owner, editor, viewer

Versions share blocks. Changing one block of a 100 MB file adds one block and one version row.

Chunking, dedup and delta sync

With fixed-size blocks, one byte inserted near the start shifts and rehashes every later block. Content-defined chunking picks boundaries from the data, so an insert only changes nearby blocks.

The block hash is the dedup key: an existing hash is never uploaded again, so re-uploads, copies and restores within an account are almost free. Dedup across accounts saves more but leaks information, because a fast upload reveals someone else has that exact file. Limit it to an account, or make the client prove it holds the bytes.

The sync protocol

Every change in a namespace gets the next seq in the journal. A device stores one cursor per namespace, fetches entries after it and applies them in order. That works the same after five seconds or five weeks offline.

To avoid constant polling, the device holds a long poll (or a WebSocket) to the notification service, which returns when the seq passes the cursor or after about 60 seconds.

Conflicts and offline edits

Two devices edit from version 6. The first commit becomes version 7. The second arrives with base_version 6 and is rejected. Don't merge arbitrary files: the server's version stays, and the client saves its edit as a "conflicted copy" beside it. Offline edits use the same path: queue changes, sync the journal on reconnect, then commit each with its base version.

Sharing works through namespaces. A shared folder is its own namespace with members and roles, and the metadata service checks the role before issuing any upload or download URL.

High-level design

  • The client watches the folder, chunks changed files (4 MB blocks are a typical choice) and hashes them.
  • The metadata service owns files, versions, the journal and permissions, and hands out short-lived pre-signed S3 URLs scoped to one block.
  • Commit writes the version and journal entry in one transaction, then publishes to SNS or a pub/sub tier to wake waiting devices.

Common traps

  • Uploading whole files through the API servers. At 12 GB/s that tier is the bottleneck, and editing a 2 GB video re-sends 2 GB.
  • Committing a version before all its blocks exist. Other devices find a version they can't download.
  • Deleting a block the latest version no longer uses. An older restorable version may still need it; collect garbage from every retained version.
  • Writing the version and its journal entry separately. A crash leaves a committed edit invisible to syncing devices.
  • One cursor for every namespace. Journals advance independently, so a busy shared folder can make another folder's changes look consumed.

Follow-up questions interviewers ask

  • "A client uploads blocks and dies before committing." The blocks are orphaned. A block is live only once a committed version references it; a cleanup job deletes the rest after a grace period that covers in-flight uploads.
  • "A device misses a notification." Nothing is lost. It reads the journal from its cursor on the next sync.

Frequently asked questions

Why split files into blocks?

+

So a client uploads only what changed, resumes failed uploads and skips blocks the server has. Versions share unchanged blocks.

How does a device find out that a file changed?

+

It holds a long poll or WebSocket to a notification service that wakes it when the namespace's journal moves. It then fetches the entries after its cursor.

What happens when two people edit the same file?

+

Each commit carries the version the client started from. The first wins; the second is rejected and saved as a conflicted copy beside the file.

Now fix it yourself.

Run the design under real traffic and see what breaks first. No signup.