Full answer
Requirements
Functional:
- Upload, download, delete and rename files and folders from web, desktop and mobile.
- Automatic sync of changes across a user's devices.
- Share files and folders with other users; keep version history.
Non-functional:
- Durability is the top priority: no file loss.
- Large files (several GB) upload reliably on poor networks; only changed parts are sent again.
- Sync changes appear on other devices within seconds.
Capacity estimates
Assumptions: 50M registered users, 10M DAU, 4 GB stored per user on average, 2 file changes per active user per day with average changed size 2 MB, 1,000 files per user, 500 bytes of metadata per file.
- Logical storage: 50M x 4 GB = 200 PB before deduplication and replication. This rules out anything except object storage with erasure coding or replication.
- Upload rate: 10M x 2 = 20M uploads per day = about 230 per second; bytes in: 20M x 2 MB = 40 TB per day, about 463 MB/s on average.
- Metadata: 50M x 1,000 files = 50B file records x 500 B = 25 TB. Too big for one database, so shard metadata.
API
POST /v1/uploads {"path": "/notes/physics.pdf", "size": 52428800,
"chunks": ["sha256:ab12...", "sha256:9f3c...", ...]}
-> {"upload_id": "u1", "missing": ["sha256:9f3c..."], "urls": {"sha256:9f3c...": "<presigned PUT>"}}
PUT <presigned URL> raw chunk bytes, straight to object storage
POST /v1/uploads/u1/commit {"base_revision": 17}
-> {"file_id": "f9", "revision": 18} or 409 if the base revision is stale
GET /v1/files/f9?revision=18 -> chunk list with presigned GET URLs
GET /v1/changes?cursor=... long-poll; returns changed entries and a new cursor
Data model
files:namespace_id(a user's root or a shared folder),file_id,path,latest_revision,is_deleted.revisions:file_id,revision,chunk_hashes(ordered list),size,modified_by,created_at.chunks:hash,size,ref_count, storage location.journal: pernamespace_id, an ordered log of changes (seq,file_id,revision) that devices read with a cursor.
Shard everything by namespace_id, so one folder tree's operations and its journal stay on one shard.
High-level design
flowchart LR
D[Desktop / mobile client] --> API[Metadata API]
API --> MDB[(Sharded metadata DB)]
API --> J[(Change journal)]
D -- presigned PUT/GET --> OS[(Object storage: chunks)]
API --> NS[Notification / long-poll service]
NS --> D2[Other devices]
OS --> CDN[CDN for downloads]How sync works
- The client watches the local folder, splits changed files into 4 MB chunks, hashes each chunk.
- It sends the chunk list; the server replies with only the hashes it does not already have. Editing one page of a 50 MB PDF usually changes one or two chunks, so only those upload. Identical files from different users are stored once (deduplication), though some services limit cross-user dedup for privacy reasons.
- Chunks go directly to object storage using presigned URLs, so API servers never carry file bytes.
- Commit creates a new revision atomically, appends to the namespace journal, and wakes long-polling devices.
- Other devices fetch changes after their cursor, download missing chunks, and rebuild the file.
Conflicts
Commit includes base_revision. If another device committed first, the server returns 409 and the client saves its version as "physics (conflicted copy from Asha's laptop).pdf". Silent last-writer-wins would lose work.
Bottlenecks and trade-offs
- Metadata hot spots: a folder shared with 10,000 people generates heavy reads; cache its listing and rate limit writes.
- Garbage collection: deleted chunks are freed only when
ref_countreaches zero and after the version retention window; run it as a careful background job. - Durability vs cost: erasure coding (for example 10 data + 4 parity fragments) stores 1.4x the data instead of 3x for triple replication, at the cost of more CPU and slower repair. Cold, rarely read versions can move to cheaper storage tiers.
- Chunk size: smaller chunks improve dedup and resume granularity but increase metadata rows; fixed 4 MB is simple, content-defined chunking finds shared regions even when bytes shift.
- Long-poll vs push: long-poll is simple and firewall friendly; mobile devices rely on push notifications to wake up.
By level
Fresher: Explain splitting files into chunks, storing them in object storage, keeping a metadata table, and notifying other devices of changes. A fresher should explain why only changed chunks are uploaded.
Mid: Estimate storage and metadata size, design the upload handshake and commit API, the revision and journal tables, and conflict handling. Expect conflict handling through a base revision check.
Senior: Cover sharding by namespace, shared folder hot spots, garbage collection, erasure coding versus replication cost, multi-region durability, and security of dedup and presigned URLs. The senior answer weighs erasure coding against replication cost.
Key points
- Content-addressed chunks give dedup, resumable uploads and delta sync
- Clients upload chunks straight to object storage with presigned URLs
- Metadata (files, revisions, chunk lists, journal) is sharded by namespace
- Devices sync by reading a per-namespace change journal with a cursor
- Stale base revision on commit creates a conflicted copy instead of overwriting
Common mistakes
- Sending file bytes through API servers
- Re-uploading the whole file on every change
- Last-writer-wins for conflicts
- Keeping all metadata in one unsharded database at tens of terabytes
Follow-ups
- How would you implement sharing a folder with another user's account?
- How do you garbage collect chunks safely?
- How would you support offline edits on mobile?
Tips
- Separate the metadata path from the bytes path immediately
- Show the "which chunks are missing?" handshake
- State durability as the top non-functional requirement
Evaluation rubric
- Clear functional and durability requirements
- Storage and metadata math with assumptions
- Chunking, dedup, journal-based sync and conflict handling
- Trade-offs on storage cost, chunk size and notification method