Explore / Backend system design
Design a File Sync Service (Dropbox)
Overview
Design a file storage and sync service like Dropbox, Google Drive or OneDrive. A user installs a desktop or mobile client, puts files in a folder, and the same files appear on their other devices and for anyone they share the folder with. They can also open files on the web, restore old versions and share links.
The trap is to design "upload a file, download a file". The interesting problems are elsewhere: a 2 GB file where one paragraph changed must not be uploaded again, millions of devices must learn about changes within seconds without polling the servers to death, two people editing offline must not silently lose each other's work, and the metadata (which files exist, where, in which version) is a harder scaling problem than the bytes. Write your answer in the Write tab and sketch the architecture in the Diagram tab.
Requirements
Functional
- Upload, download, rename, move and delete files and folders from desktop, mobile and web.
- Automatic sync: a change on one device appears on the user's other devices.
- Share folders with other users (read or edit) and share files by link.
- File version history and restore; recover deleted files for a period.
- Work offline and sync when back online.
Non-functional
- Never lose data: durability is the top priority, well above latency.
- Fast sync: a small change shows up on other online devices within a few seconds.
- Efficient: upload and store only what changed; resume interrupted transfers.
- Scale: hundreds of millions of users, hundreds of billions of files, files up to tens of GB.
- Correct under concurrency: no silent overwrites when two devices change the same file.
Estimates
Assume 500 million users, 100 million daily active users with 2 file changes per day each, an average of 1 MB of new data per change after removing unchanged parts, about 500 files per user, and around 500 bytes of metadata per file version. Work out:
- File changes per second, average and peak (3×).
- New block data per day, and the raw disk it needs if each block is erasure-coded at 1.5× in each of two zones.
- Total file metadata, and whether it fits in one database.
- How many devices hold an open "tell me about changes" connection.
Hints
- If a user edits one page of a 500 MB video project, what exactly needs to travel over the network?
- Two users upload the same 1 GB file. Should you store it twice?
- Should the server that tracks file names and versions also handle the bytes?
- How does a laptop learn that something changed on the phone without asking every few seconds?
- Two devices edit the same file offline, then both reconnect. What should the user end up with?
Follow-ups
- How would you let a user restore a folder to how it looked last Tuesday?
- How do you delete data when a user deletes a file, if blocks are shared between files?
- How would you add real-time collaborative editing, like Google Docs?
- A user moves a folder with 100,000 files. What happens on the server and on other devices?
- How do you protect against a client that claims to have uploaded blocks it doesn't have?
Write your answer step by step and compare it with the reference solution on GrindPrep.