Catalog My learning Blog
System Design Interview Prep: Framework and Questions · Phase 1 · Lesson 10 · 6 min read

Design Dropbox: File Storage Interview Answer

On this page
  1. The problem: design Dropbox or Google Drive
  2. File storage requirements and scale
  3. Separate metadata from file content
  4. Chunking and deduplication by content hash
  5. The deduplication security trap
  6. Sync and conflict resolution
  7. What a strong file storage answer includes
  8. Check yourself

The problem: design Dropbox or Google Drive

"Design a file storage and sync service like Dropbox." Users upload files, see them on all their devices, share folders, and get older versions back. Files can be gigabytes. Work through requirements and a first sketch yourself, then compare.

File storage requirements and scale

Functional: upload and download files; automatic sync across a user's devices; share files and folders; version history.

Non-functional: never lose a file; don't re-upload a whole file for a small change; storage cost matters at this scale; sync can lag by seconds.

Estimate. 100 million users storing 10 GB each is about 1 exabyte of data. At that size, saving even 20 percent through deduplication is a huge amount of money, and the metadata (names, folders, permissions) is tiny by comparison.

Separate metadata from file content

The bytes and the information about them behave completely differently, so they live in separate systems:

WhatWhereWhy
Names, folders, owners, sharing, versionsMetadata service on a relational databaseSmall, queried in many ways, needs transactions
File contentObject storage (blob store) such as S3Huge, written once, read by key, must be durable and cheap

The metadata database answers "what's in this folder?" and "who can see this file?". The blob store answers "give me the bytes for this key". Neither does the other's job well.

The bytes shouldn't pass through your API servers either. The metadata service checks permissions and hands the client a short-lived presigned URL, and the client uploads straight to object storage (AWS docs). Combined with the chunks below, uploads also become resumable: a dropped connection costs one chunk, not the whole file.

Chunking and deduplication by content hash

Split each file into fixed-size chunks, a few megabytes each. Dropbox splits files into 4 MB blocks and hashes each one with SHA-256 (Dropbox, 2014). Name each chunk by the SHA-256 hash of its content. A file version is then just an ordered list of chunk hashes.

Uploading becomes a conversation. The client hashes its chunks and asks the metadata service which hashes it already has. It uploads only the missing ones, then commits the new list. That one technique gives you two features:

  • Partial sync. Edit the middle of a big file and only the changed chunk uploads.
  • Deduplication. If any user already uploaded identical content, those chunks are never stored twice. There's a security catch, covered below.

A quick test with a 40 MB file in 4 MB chunks:

Python
# chunks.py: which chunks need uploading after an edit?
import hashlib, os

CHUNK = 4 * 1024 * 1024                                   # 4 MB

def chunk_hashes(data: bytes) -> list[str]:
    return [hashlib.sha256(data[i:i + CHUNK]).hexdigest() for i in range(0, len(data), CHUNK)]

original = os.urandom(40 * 1024 * 1024)                   # a 40 MB file: 10 chunks
known = set(chunk_hashes(original))                       # what the server already has

overwrite = original[:20_000_000] + b"EDIT" + original[20_000_004:]   # change 4 bytes in place
insert = b"EDIT" + original                                           # add 4 bytes at the start

for name, data in [("overwrite in the middle", overwrite), ("insert at the start", insert)]:
    hashes = chunk_hashes(data)
    print(f"{name}: upload {sum(h not in known for h in hashes)} of {len(hashes)} chunks")
Code
overwrite in the middle: upload 1 of 10 chunks
insert at the start: upload 11 of 11 chunks

The second line is the follow-up a sharp interviewer will ask about. Inserting bytes shifts every fixed boundary, so every chunk looks new. Content-defined chunking fixes it: chunk boundaries are placed where a rolling hash of the data matches a pattern, so boundaries move with the content and an insertion changes only the chunks around it.

The deduplication security trap

If the server answers "I already have that chunk" to anyone who sends its hash, the hash becomes a key to the file. Researchers showed this against Dropbox in 2011: a modified client could claim a file by sending only its hashes, and the file was linked to the attacker's account (Mulazzani et al., USENIX Security 2011). Dropbox later stopped deduplicating on the client side. The safe design: skip uploads only for chunks the same user already has, and deduplicate across users on the server, after the bytes have arrived. That also closes a quieter leak: an instant "already uploaded" answer tells a user that someone else stores that exact file.

The client splits a file into chunks and hashes each one. Names, folders, sharing and versions live in a metadata service on a relational database, while the bytes live in blob storage keyed by chunk hash. A chunk that already exists is not uploaded again, and a changed file re-uploads only the chunks that changed.
The client splits a file into chunks and hashes each one. Names, folders, sharing and versions live in a metadata service on a relational database, while the bytes live in blob storage keyed by chunk hash. A chunk that already exists is not uploaded again, and a changed file re-uploads only the chunks that changed.

Sync and conflict resolution

Each file has a version number in the metadata service. A client commits a new version by saying "this replaces version 7". If the server is already at version 8, because another device committed first while this one was offline, that's a conflict. Don't silently overwrite. Keep both, saving one as "report (Sam's laptop conflicted copy)", the way Dropbox does, and let the user decide.

Devices learn about changes through a notification channel (a long-lived connection or long polling) that says "folder X changed"; they then fetch the new metadata and download only chunks they don't already have.

What a strong file storage answer includes

  • Metadata and blobs separated, with reasons.
  • Chunking with content hashes, giving partial sync and dedup together.
  • Uploads that go straight to object storage through presigned URLs.
  • Cross-user deduplication done on the server, so a hash alone never grants access.
  • The insertion problem and content-defined chunking, if time allows.
  • Version numbers for conflict detection, and a non-destructive conflict policy.
  • Durability: the object store replicates across machines or data centers; deleting a chunk requires knowing no file version still references it.

Check yourself

Content is huge, binary and accessed by key, while metadata is small and queried relationally. Object storage is far cheaper and more durable for bytes, and keeping them out keeps the database small and fast.

One copy is stored, because both versions reference the same chunk hashes. But the second user should still send the bytes; the server deduplicates after they arrive. If sending hashes alone were enough, anyone who knew a file's hashes could claim the file.

Only when no file version anywhere still references it, because deduplication means many files can share one chunk. Track references with reference counts updated alongside the metadata, or run a periodic garbage-collection pass that finds unreferenced chunks, and keep a grace period so in-flight uploads aren't broken.

If uploading a file is instant when someone else already stored it, an attacker can learn whether a given file exists in the system, such as a specific document. Limiting deduplication to one user's own files, or always uploading the bytes, closes that side channel.

When both sync, the server sees two versions derived from the same parent. Rather than silently overwriting, it keeps both, typically saving one as a conflicted copy for the user to resolve. Text formats can sometimes be merged automatically.