A file storage and sync service lets you save files in the cloud, open them from anywhere, and see a change made on your laptop show up on your phone a few seconds later. The hard parts are the size of the files, up to 50 GB, and keeping many devices in step without losing anyone's work. The answer to both is to split files into chunks and keep a small metadata record next to them. This page runs it through the Interview Approach, one step at a time.
1. Functional requirements#
Three actions define the product:
- A user can store files, such as pictures and videos.
- A user can retrieve those files.
- A user's changed files sync across all their devices.
One constraint shapes everything else: a single file can be up to 50 GB.
Out of scope: sharing files with other users, real-time co-editing of documents, search inside files, and previews or thumbnails.
2. Non-functional requirements#
These four qualities shape the design:
| Quality | Requirement |
|---|---|
| Scalable | Hold 10 billion files for 100 million daily active users |
| Availability over consistency | Uploads and downloads keep working when parts fail. Another device may see a change a few seconds late |
| Low sync latency | A change on one device reaches the user's other devices in under 1 minute |
| Fault tolerant | Once a file is saved, it is never lost |
A quick estimate shows which numbers change the design:
- Storage: 10 billion files at an average of 1 MB is about 10 PB of file data. That can't live in a database, so file bytes go to blob storage and the database only holds metadata.
- Metadata: 10 billion rows at about 1 KB each is about 10 TB. Too big for one comfortable Postgres instance for long, so plan to shard.
- Large files: a 50 GB file over a 100 Mbps connection takes over an hour. One dropped connection must not restart the whole upload, so uploads have to be chunked and resumable.
- Sync checks: if 100 million devices each asked "anything new?" every 30 seconds, that's over 3 million requests per second, almost all answered "no". Asking is too expensive; the server should tell devices when something changes.
3. Actors#
Two actors talk to the system, one person and one piece of software:
| Actor | What they do | Access |
|---|---|---|
| User | Uploads, downloads and opens files through the client app | Signed in, sees only their own files |
| Sync agent | Runs in the background on each of the user's devices. Uploads local changes and pulls remote ones | Acts with the user's credentials, one per device |
The sync agent is what makes this a sync service and not just storage. It watches the local folder, so the user never has to upload by hand.
4. API routing#
Three endpoints cover upload, download and sync. They go through an API gateway and load balancer to the servers:
| Purpose | Endpoint | Response |
|---|---|---|
| Upload a file | POST /v1/files |
201 with the file ID |
| Download a file | GET /v1/files/{fileId} |
The file, streamed in chunks, plus its metadata (optional) |
| Get changes between local and remote | GET /v1/files?changed_since={timestamp} |
A list of the files that changed since that time |
The upload request carries the file and its metadata:
{
"file": binary,
"metadata": FileMetadata
}
FileMetadata holds the name, path, size and content type. Step 6 changes how the bytes travel for large files, but the three routes stay the same.
5. High-level design#
Build the design one functional requirement at a time. Five boxes are enough: client, API gateway, server, blob storage (S3) and a Postgres database.
Store a file (requirement 1). The client sends POST /v1/files through the API gateway to a server. The server splits the file into chunks, stores each chunk in blob storage such as S3, and gets a URL back for it. Then it writes the file's metadata to Postgres:
| Column | Meaning |
|---|---|
id (primary key) |
File ID |
user_id |
Owner of the file |
metadata |
Name, path, size, content type |
s3_url |
Where the file's chunks live in blob storage |
created_at |
When the file was first stored |
updated_at |
When the file last changed |
chunks |
Ordered list of {chunk_id, metadata}, where chunk metadata is its index, size and hash |
Noting down the chunks is what makes the rest possible. The file in blob storage is just a set of pieces, and this list says which pieces make up the file and in what order.
Retrieve a file (requirement 2). The client sends GET /v1/files/{fileId}. The server reads the metadata, fetches the chunks in order, and streams them back to the client chunk by chunk. The client replays the chunks in order to rebuild the file and shows it to the user. Nothing ever holds a whole 50 GB file in memory.
Sync across devices (requirement 3). A sync agent on each device handles both directions.
Syncing a change from the current device:
- The agent observes changes on the device: new content, renamed files, and changed modified dates and times.
- It puts each change, with its metadata, on a local queue and works through it, calling the same upload endpoint. Only the chunks that changed are uploaded.
- The server stores the new chunks in S3 and gets their URLs back.
- The server updates the database with the new metadata and a new
updated_at. If two devices change the same file, the latest change wins.
Syncing to the other devices:
- The user opens a file or folder, or the server pushes a change notice to the agent.
- The agent compares the local state with the cloud state by calling
GET /v1/files?changed_since={timestamp}with the time of its last sync. - On a mismatch, it calls the download endpoint to get the latest metadata.
- It downloads only the changed chunks, rebuilds the file and shows it to the user.
6. Address the non-functional requirements#
The basic design works for small files on a quiet day. Now take each quality and find where it breaks.
Large files (the 50 GB constraint)#
Sending a 50 GB file in one request body through the API gateway and server fails three ways. Connections drop, the servers spend all their bandwidth copying bytes, and any failure restarts from zero. Three changes fix it:
- Chunk on the client. The client splits the file into chunks of about 5 MB, so a 50 GB file is about 10,000 chunks. It hashes each chunk (for example SHA-256) and sends only the metadata and the chunk list in
POST /v1/files. - Upload straight to blob storage. The server answers with a short-lived pre-signed URL for each chunk, and the client uploads the chunks directly to S3, in parallel. The server only handles metadata. When every chunk has arrived, the client tells the server and the file is marked complete.
- Resume, don't restart. The server records which chunks have arrived. After a dropped connection, the client asks which chunks are missing and uploads only those.
Hashes give a bonus. If a chunk with that hash already exists, the client skips it, which makes edits cheap: change one page of a large file and only one or two chunks travel. Downloads work the same way in reverse, with pre-signed URLs, so the client downloads only changed chunks. The trade-off is a smarter client and many more metadata rows, since each file now has a list of chunks to track.
Low sync latency (under 1 minute)#
Agents asking changed_since on a timer either miss the 1-minute target or flood the servers, as the estimate showed. Push instead:
- After a file's metadata is updated, the server publishes a change event to a queue or pub/sub topic, keyed by user.
- A notification service holds an open connection (WebSocket or long poll) to each online agent and pushes a short "something changed" message to that user's other devices.
- The agent then calls
changed_sinceand downloads only the changed chunks.
The push carries no file data, so a lost message only delays sync. As a safety net, agents also check changed_since every few minutes and when they reconnect. The trade-off is millions of open connections to manage.
Use a server-assigned value for changed_since, not the device's clock. Device clocks drift, and a device that is a minute behind would miss changes. A per-user change counter that increases with every update is even safer than a timestamp.
Availability over consistency#
One server and one database would take the whole service down when either fails. Run several stateless servers behind the load balancer, and add read replicas of Postgres in several availability zones. If a replica or server fails, traffic moves to the others.
The cost is that devices may briefly disagree, which is the availability over consistency choice from step 2. The bigger question is conflicts: two devices edit the same file while one is offline. "Latest change wins" is simple, but it silently throws away the other edit. A safer version keeps the latest change as the file and saves the losing edit as a conflicted copy, so nothing is lost and the user decides.
Fault tolerance#
"Files have to be saved" means durability. Blob storage like S3 already copies every chunk across several availability zones, so chunk data is safe once the upload succeeds. The metadata needs the same care: run Postgres with a synchronous standby so a committed row survives the loss of the primary, and take regular backups.
Order matters. Write the metadata only after every chunk is confirmed in blob storage, so a file record never points at missing data. If an upload is abandoned halfway, its chunks are orphans; a background job deletes chunks that no file references after a day or so. Keeping old versions of the chunk list for a while also lets a user restore a file they deleted or overwrote by mistake.
Scalable#
File bytes scale with blob storage, which grows without any work from you. The metadata is where scale bites: 10 billion files and a burst of updates every time devices sync. Shard the metadata by user_id. Every request, including changed_since, is about one user's files, so each one goes to exactly one shard.
Inside a shard, index (user_id, updated_at) so changed_since reads a small range and never scans the table. Store chunks in their own table keyed by file ID once the chunk lists get long, instead of one large column on the file row.
Whiteboard sketch#
The sketch below is the design from steps 5 and 6: a client and a sync agent talking to servers through an API gateway, with file chunks in S3 and metadata in Postgres.

Key takeaways#
- Three functional requirements: store files, retrieve them, sync changes across devices. Files can be up to 50 GB.
- File bytes go to blob storage, and Postgres keeps only metadata and the ordered list of chunks.
- Chunk files on the client (about 5 MB each), hash every chunk, and upload straight to blob storage with pre-signed URLs. Uploads resume instead of restarting.
- Hashes mean only changed chunks travel, in both directions.
- A sync agent on each device uploads local changes and pulls remote ones with
changed_since. - Meet the 1-minute sync target with push notifications, plus an occasional
changed_sincecheck as a safety net. Use a server-side counter or timestamp, never the device clock. - Choose availability, and keep the losing edit of a conflict as a copy instead of discarding it.
- Write metadata only after the chunks are stored, and shard metadata by
user_id.