Scrivio Interview library
DesignFoundations7 min read · updated 13 November 2026

A file storage and sync service keeps a folder in step across a person's laptop, phone and the web, lets people share folders, and keeps earlier versions of each file. Files range from a few bytes to tens of gigabytes.

Design the API and data model of a file storage and sync service, including how large files are uploaded and how a second device learns that a file changed.

Files are split into blocks of a few MB, each named by its content hash; the client asks which hashes the server lacks, uploads only those to object storage, and then commits a file version that lists its block hashes. Metadata (namespaces, file entries, versions and a per-namespace change journal) lives in a relational store sharded by namespace. A second device keeps a cursor per namespace, is told by a long poll or push that something changed, calls list_changes(cursor), and downloads only the blocks it is missing.

Why this question is asked

File sync looks simple from the outside: a folder that appears the same everywhere. Underneath, it is a careful split between bulk bytes and small, strictly ordered metadata, and interviewers ask it to see whether we make that split and whether we know how one device finds out about another device's change without polling the whole folder. In this answer, we will size the problem, see why files are stored as content-addressed blocks, walk through an upload, design the metadata tables, place each kind of data in the right store, and follow a change to a second device.

1Requirements and Rough Numbers

People keep a folder in step across a laptop, a phone and the web, share folders with others, and can restore earlier versions. Files range from a few bytes to tens of gigabytes. Suppose 50 million users with 3 devices each and 2,000 files per user on average: that is 100 billion file entries and a few exabytes of raw data before deduplication. Most activity is small: a few edited files per user per day, and devices that mostly just ask whether anything changed. So the design must make the common case, a small change or no change, very cheap, and the rare case, a 20 GB upload, reliable.

2Why Files Become Content-Addressed Blocks

Instead of storing a file as one object, the client cuts it into blocks of a few MB, say 4 MB, and computes the SHA-256 hash of each block. The hash becomes the block's name. This is called content addressing: the name is derived from the content, so two identical blocks always have the same name.

That choice pays off three times. Uploads resume block by block, so a dropped connection at 15 GB of 20 GB loses at most one block. Unchanged blocks are never sent again, because the server already has a block with that hash. And identical content is stored once, which is called deduplication: the same 300 MB installer in a million folders is kept as one set of blocks.

3Uploading a File, Step by Step

An upload is a short conversation with the metadata service followed by bulk transfers to object storage. The client first sends the list of block hashes for the new file. The server answers with the hashes it does not have. The client uploads only those blocks, and then commits a new file version that lists all the block hashes in order.

Step throughUploading report.pdf (3 blocks, 1 new)
ClientMetadata APIBlock storage
need_blocks([h1, h2, h3])
missing: [h3]
PUT block h3 (pre-signed URL)
verify SHA-256(bytes) == h3
commit(ns 7, /docs/report.pdf, [h1, h2, h3], base v4)
check every listed block exists
version 5, journal cursor 9182

7 messages in order. Play them, or step through them one at a time.

Notice that the commit is the only moment the file changes for everyone else. Blocks uploaded without a commit are invisible and are cleaned up later, so a half-finished upload never shows a half-written file.

4The Metadata Model

The metadata is small, structured and needs transactions, so a relational database such as PostgreSQL or MySQL fits well. A namespace is the unit of sharing: each user's root folder is one namespace, and each shared folder is another.

Java
namespaces (ns_id, owner_id, kind) -- kind: ROOT | SHARED
file_entries (ns_id, path, file_id, latest_version, deleted, PRIMARY KEY (ns_id, path))
versions (file_id, version, block_list, size, author_device, created_at)
-- block_list: [h1, h2, h3]
journal (ns_id, cursor, file_id, version, op) -- op: ADD | EDIT | DELETE | MOVE
-- cursor increases by 1 per change
-- block contents are not here; they are objects named by hash:
-- s3://blocks/ab/cd/abcd93f1...

The journal is the heart of sync. Every commit in a namespace appends one row with the next cursor number in the same transaction that updates the file entry and inserts the version. Deleting a file only sets the deleted flag and journals it, so other devices learn about it and old versions stay restorable.

5Placing Each Kind of Data in the Right Store

Block content goes to object storage such as Amazon S3, deduplicated by hash. Object storage is cheap per GB, very durable and scales without our help, which suits petabytes of immutable blocks.

Metadata goes to the relational store, sharded by namespace. Sharding means splitting the data across many database servers; choosing the namespace as the shard key puts every file entry, version and journal row of one folder on the same server. The reason is ordering: the cursor of a namespace can be a simple increasing number handed out in one transaction, so every device sees that folder's changes in exactly the same order. A very large namespace can still fit on one shard, since even a million entries are only hundreds of MB of metadata.

Step throughWhere each piece lives
  1. Sync clientslaptop, phone, web; a cursor per namespace
  2. Notification servicelong polls or push: only 'something changed'
  3. Metadata APIneed_blocks, commit, list_changes
  4. Metadata database, sharded by namespaceentries, versions, journal
  5. Block storageS3-style objects named by SHA-256

5 layers, from the top down. Step through them one at a time.

6How a Second Device Learns About a Change

Each device stores, for every namespace it syncs, the last cursor it has applied. It does not poll the folder. Instead it holds a long poll to a notification service, a request the server keeps open for up to a minute and answers early if the namespace changes, or it receives a mobile push. The notification carries no file data; it only says that namespace 7 has news.

The device then calls list_changes(ns 7, cursor 9181) and gets every journal entry after 9181: the new version of report.pdf with block list [h1, h2, h3]. It already has h1 and h2 locally, so it downloads only h3, rebuilds the file in a temporary place, checks it, moves it into the folder, and stores cursor 9182. If the device was offline for a week, the same call simply returns more entries.

Java
POST /notify/longpoll {"ns": {"7": 9181}} // held open ...
-> {"changed": [7]} // returned when commit 9182 lands
POST /list_changes {"ns": 7, "cursor": 9181}
-> {"entries": [{"path": "/docs/report.pdf", "version": 5,
"blocks": ["h1", "h2", "h3"]}], "cursor": 9182, "has_more": false}
GET /blocks/h3 // only the missing block

7Integrity: Verified, Resumable, All or Nothing

Every block is verified by hash when it arrives: the storage side computes SHA-256 of the received bytes and rejects the block if it does not match its name, so corruption in transit can never be stored under a good name. Uploads resume block by block, since the client simply asks need_blocks again and sends what is still missing. And a commit fails cleanly if any listed block is missing, so a version can never point at content the server does not have.

8Follow-up questions

What privacy concern does deduplication across users raise?

If the server skips the upload whenever a block already exists anywhere, the client learns that some other user stored that exact content. An attacker can use this as a test: try to upload a known document, such as a leaked file or a template with a guessed salary filled in, and watch whether the upload is skipped. Mitigations are to deduplicate only within a user or namespace, to always upload and deduplicate silently on the server side, or to require proof that the client really has the content. Client-side encryption with per-user keys also prevents cross-user deduplication, which is a deliberate trade of storage for privacy.

Why is the path not the primary identity of a file?

Because files get renamed and moved. A move is a metadata change on the entry, and keeping a stable file_id lets versions and history follow the file instead of being lost or duplicated on every rename.

Why long polling instead of devices polling every few seconds?

With 150 million devices, polling every 30 seconds would be 5 million requests per second, nearly all answering 'nothing changed'. A long poll costs one open connection per device and a reply only when there is news, which is far cheaper for both servers and phone batteries.

9Conclusion

In this answer, we designed a file sync service around a split between blocks and metadata. Files become content-addressed blocks of a few MB, so uploads send only missing blocks, resume block by block and deduplicate by hash in object storage. Metadata, namespaces, file entries, versions and a per-namespace journal with an increasing cursor, lives in a relational store sharded by namespace so each folder's changes are ordered in one place. A second device learns of a change through a lightweight notification, calls list_changes with its cursor, and downloads only the blocks it lacks, while hash checks and all-or-nothing commits keep data intact.

What to say in the interviewAbout 80 seconds aloud

Open with

I would separate block content from metadata. The client splits each file into blocks of about 4 MB and names each by its SHA-256 hash. To upload, it sends the list of hashes, the server answers with the ones it lacks, the client uploads only those to object storage through pre-signed URLs, and then commits a file version listing the block hashes.

Then, if they want more

That makes uploads resumable and deduplicated. The metadata model has namespaces, which are a user's root or a shared folder, file entries with namespace, path, latest version and a deleted flag, versions with the block list, size, author and time, and a per-namespace change journal with an increasing cursor.

Blocks live in object storage keyed by hash; metadata lives in a relational database sharded by namespace, so each folder's changes are ordered in one place. For sync, each device keeps a cursor per namespace.

A long poll or push only tells it that something changed; then it calls list_changes with its cursor, gets the new versions and block lists, and downloads only blocks it does not have. Blocks are verified by hash on upload, and a commit fails cleanly if any listed block is missing, so a version never points at missing data.

About this answer

Last updated
13 November 2026
Checked
Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
Where the question comes from
Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer

Copy the line below and send it to the author with what you found. It carries the address of this page.

Issue with "Design the API and data model of a file storage and sync service, including how large...": https://scrivio-interview-library.netlify.app/architecture/system-design-problems/40d389f02a/