System design case study C14 · Storage · Sync

Design a File Sync Service (Dropbox-style)

Keep folders identical across a laptop, a phone and the cloud, transferring as few bytes as possible, and never silently losing anyone's edits.

What you'll be able to explain
  • Split files into content-addressed chunks
  • Deduplicate and transfer only changed chunks
  • Keep metadata in a strongly consistent store with a change journal
  • Notify devices of changes and sync them efficiently
  • Resolve conflicts and keep version history

Scope

Functional

  • Upload/download files of any size; sync a folder across devices.
  • Version history and restore; sharing with other users.
  • Offline edits sync later.

Non-functional

  • Durability: never lose a committed file version.
  • Efficient: small edits to large files upload only the changed parts.
  • Changes appear on other online devices within seconds.

Size

  • 100M users, average 10 GB → 1 EB logical; deduplication typically saves 30%+.
  • 1B file changes/day → ~12k/s metadata commits.

Chunks and metadata

  • Files are split into chunks (fixed 4 MB, or content-defined chunking with a rolling hash so an insertion near the start doesn't shift every chunk boundary).
  • Each chunk is identified by its SHA-256 hash and stored in object storage under that hash: identical chunks are stored once across all users.
  • A file version = ordered list of chunk hashes + metadata.
Store Contents
Block store (object storage) chunk_hash → bytes (encrypted)
Metadata DB (sharded SQL by namespace) namespaces, files, versions, chunk lists
Journal per-namespace ordered log of changes (cursor-based)

The architecture

CLIENTLaptopCLIENTPhoneSERVICEMetadata serviceDATABASEMetadata DB+ journalSERVICEBlock serviceOBJECT STOREObject storechunks by hashSERVICENotification svclong-poll / WS1 which chunks missing?2 upload missing3 commit versionnamespace changed4 changed!5 list changes since cursor
Sync: clients upload only missing chunks, then commit metadata; others are notified and pull.

The 30-second summary

Say it in the interview

"Files are split into content-defined chunks addressed by hash and stored once in object storage, which gives deduplication and delta uploads. Metadata lives in a sharded, strongly consistent store with a per-namespace journal; commits are conditional on the base version, and conflicts produce a 'conflicted copy'. Devices get lightweight change notifications and pull changes from their journal cursor, so sync is resumable and robust."

Follow-up questions the interviewer may ask

  1. How do you sync a 2 GB file where only 1 MB changed?
  2. How do clients learn about remote changes quickly?
  3. How do you share a folder with another user?
  4. How do you restore a deleted file?

Model answers to each of these are in the book.