Case study V.11Advanced

Design a File Sync Service Like Dropbox

Users expect every file on every device, always, and never a lost edit. Splitting files into blocks named by their content makes uploads small, storage deduplicated, and sync a matter of comparing lists of hashes.

The short answer

Requirements. Upload and download files of any size, sync them across devices, keep version history and share files and folders; never lose a file, send as few bytes as possible, keep metadata strongly consistent, at hundreds of petabytes.

Commits
5,800 per second500M file changes a day
Storage
500 PB100M users × 5 GB, before deduplication
Block size
about 4 MBa typical edit uploads one block

The design. Files are split into blocks of about 4 MB named by their SHA-256 hash, so a client uploads only the blocks the server lacks and identical blocks are stored once. A commit lists the new version’s block hashes and the version it was edited from, and the metadata database accepts it only if that version is still the latest; otherwise the client saves a conflicted copy. Each folder has an ordered journal on one shard, and every device long polls it with a cursor to pull the changes it has not seen.

Interview prompt

Design Dropbox or Google Drive: files placed in a folder appear on all of a user’s devices and can be shared with others.

Requirements and estimates

Functional requirements

  • Upload and download files of any size.
  • Automatic sync across devices.
  • Version history and restore.
  • Share files and folders.

Non-functional requirements

  • Durability above all: never lose a file.
  • Sync quickly while sending as few bytes as possible.
  • Metadata is strongly consistent.
  • Hundreds of petabytes.

Estimates

Commits   500M file changes per day          ≈ 5,800 commits/s
Storage   100M users × 5 GB                  = 500 PB before deduplication
Upload    a typical edit changes one 4 MB block, not the whole file

API and data model

API

POST /v1/blocks/check { hashes: [...] }
→ which hashes the server is missing
PUT  /v1/blocks/{hash}       one 4 MB block
POST /v1/files/commit
{ path, baseVersion, blockHashes: [...] }
GET  /v1/changes?cursor=c_9812   long poll

Data model

files     file_id, namespace_id, path,
          latest_version
versions  file_id, version, block_hashes[],
          size, device_id, created_at
blocks    hash PK, storage_key, ref_count
journal   namespace_id, seq, file_id, version

Whiteboard

What you sketch in the first five minutes, before any of the detail below. Draw the blocks, then the race between two devices.

1. Blocks named by their hash

Say: never move a whole file when one part changed, and never store the same bytes twice.

report.pdf, 12 MB = 3 blocks of 4 MBa3f…9c1…77e…version 7a3f…b2d…77e…after an editeach block is named by its SHA-256 hashlaptopblockserviceblockshave these 3?missing: b2dupload b2d only: 4 MB, not 12the same block from a million users is stored once
  1. Split each file into blocks of about 4 MB and name each by its SHA-256 hash.
  2. Ask the server which hashes it already has.
  3. Upload only the missing blocks to object storage.

Next question: insert one byte at the start and every fixed block shifts. Content defined chunking moves the boundaries with the content, so only one or two blocks change.

2. The commit check

Say: a block never changes once written, so all the hard consistency lives in the metadata.

folder journal, on one shardverchange6edit report7add photo8edit reportlaptopphonebase 7 ✓base 7, but latest is now 8: rejectedsave "report (conflicted copy)"latestone transaction:check the base,append, bumpevery device long polls the journal with a cursor
  1. Commit the new block list with the version it was edited from, its base.
  2. Accept only if the base is still the latest: append to the journal and bump the version in one transaction.
  3. Rejected? Save the edit as a conflicted copy, never overwrite.

Next question: why one shard per folder? So the folder's journal has one strict order that every device can follow with a cursor.

File chunking and block deduplication

Split each file into blocks of about 4 MB and name every block by its SHA-256 hash. Before uploading, the client asks which hashes the server already has and sends only the missing ones. The same block stored by a million users is kept once. Fixed size blocks have one weakness: inserting a byte near the start shifts every boundary. Content defined chunking places boundaries with a rolling hash, so they move with the content and an insert changes only one or two blocks.

The commit protocol and sync conflicts

  1. Upload missing blocks to object storage.
  2. Commit the new version with its block list and the baseVersion it was edited from.
  3. The server accepts only if baseVersion is still the latest, appends to the folder’s journal and bumps latest_version, all in one transaction.
  4. If another device committed first, the commit is rejected and the client saves its edit as a conflicted copy instead of overwriting.

Metadata lives in a relational database sharded by namespace (a user’s root or a shared folder), so each folder’s journal is on one shard and strictly ordered. Devices remember their position in the journal as a cursor and long poll for anything newer.

What the interviewer probes next

A 2 GB upload fails at 80%.

Blocks already uploaded stay on the server. The client asks again which hashes are missing and resumes from there.

How do deletes free up space?

Deletes are soft and kept in version history for a period. A garbage collector removes blocks whose reference count has reached zero.

A shared folder has 10,000 members.

The folder is its own namespace with one journal. Members’ devices follow that journal, and change notifications fan out through pub/sub.

Why not store files in the database?

Large blobs bloat the database and its backups. Object storage is far cheaper per byte and built for durability; Amazon S3 is designed for eleven nines.

Building blocks used here

Want to run this as a mock interview? See interview prep.

© 2026 Arman Ajabkhani · armantik.com · Privacy