Loading...
A 20-minute mock system design interview. You drive the pace. Jump to the board when you are ready; skip capacity math if you want. The interviewer grades your thinking, not a template match.
Two shared surfaces (only one is on screen at a time; use the panel arrow to switch):
Build incrementally while you talk. Trace one file edit end to end through your diagram: laptop saves, phone receives. Argue the tradeoff, not "industry standard."
Read this before you go in. These are the decisions, and why they matter.
The trap is "upload the whole file on every save." A one-line fix in a 2 GB project file should not cost 2 GB of upload on a phone plan.
Split every file into fixed 4 MB chunks (Dropbox's real block size). Hash each chunk with SHA-256. On save, the client re-hashes and compares against what it already uploaded. Only the chunks whose hash changed cross the network. This is delta sync, the rsync idea applied to cloud storage. It also means a failed transfer retries one chunk, and identical chunks anywhere in the system can be stored once.
Why 4 MB and not 4 KB or 400 MB: too small and you drown in per-chunk metadata and requests; too large and a tiny edit re-ships a big block and dedup gets coarser. The right size comes from the storage device's utilization and IOPS, typical network bandwidth, and average file size. Content-defined chunking (Rabin fingerprints, as in rsync) survives insertions better than fixed boundaries. Equally defensible if you can say why.
Each chunk is compressed (gzip or bzip2 for text; media usually skips it) and encrypted before it lands in storage. The requirement says encrypted at rest. Say where that happens and where the key lives.
In most questions the client is a dumb box. Here it is four cooperating parts, and drawing it that way is a strong signal. Put them in a Note attached to your client:
Client etiquette: exponential backoff against busy servers; mobile syncs on demand to save battery and data; desktop syncs eagerly.
Never route file bytes through the servers that handle folder trees. Two planes:
A new upload runs both legs in parallel. The metadata leg records the file as pending, so other devices can be told "upload in progress." When the last chunk lands, the storage side calls back and the row flips to uploaded; only then do other devices hear "file ready." That status transition is what keeps a device from downloading a half-written file.
Why not let the client upload straight to S3 with a presigned URL? Faster, one hop, and a real option. But then chunking, compression, and encryption have to be reimplemented on iOS, Android, desktop, and web, and encryption inside a client the user controls can be tampered with. Block servers centralize that logic at the cost of one extra hop. Either answer is fine if you name the trade.
Two users should never see a shared file in two different states at the same time. Metadata wants strong consistency, which is why the reference uses a relational database with native ACID transactions: the new version row and the "latest version" pointer commit together. A NoSQL store can work, but you end up rebuilding those guarantees in the sync logic, and the interviewer will ask you how.
Cache the metadata, but invalidate on every write. A stale cache here shows two devices two different folder trees.
Conflicts. Two people edit the same file at the same instant. The first commit the sync service processes wins. The second arrives with a stale base version and is rejected as a conflict. The loser's client keeps both copies, its local edit and the server's latest, and the human merges. Never silent last-write-wins: data loss is unacceptable, so conflicts surface to people instead of disappearing.
You promised strong consistency and offline editing. Reconcile them: an offline edit is a deferred write against possibly stale state. It flows through the same conflict check on reconnect. Server state stays strongly consistent; the edges are reconciled by humans.
Clients must not poll the metadata service every second. Something has to tell them.
Long polling is the reference choice, and Dropbox's real one. The channel is one-directional (server to client), notifications are infrequent, and there are no bursts. A WebSocket keeps a bidirectional channel open for traffic that never comes back the other way; that is over-engineering for this shape, but defensible if you argue it. The loop: client opens a long poll; the server answers when something changes; the client closes it, fetches the metadata delta, downloads the missing chunks, and re-opens a poll. On timeout, re-poll.
Behind the notification tier: one global request queue that all client updates enter, consumed by many sync service instances, so load balancing comes for free. And one response queue per device. A queue deletes a message once one consumer reads it, so a shared queue cannot broadcast to three devices. That semantic forces per-device queues, and it hands you offline sync as a side effect: a device that is off finds its messages waiting when it returns. If you use Kafka instead, per-device consumer offsets on a per-user topic achieve the same thing; say so.
The workload surprises people. Uploads are a few thousand per second, which is small. The state is petabytes, and the open connections are hundreds of millions. Money goes to storage, not compute.
Method: users × files × size for state; DAU × uploads per day for rate; open devices ÷ connections per server for the notification fleet. Rough numbers are fine; the method is what gets graded.
Block server dies mid-upload: the client retries the chunk on another server; chunks are idempotent by hash. Metadata master dies: promote a replica; the pending status means nothing half-committed is visible. Blob store region fails: cross-region replication, because data loss is the one unacceptable outcome. Notification server dies: about a million long polls drop at once. Clients reconnect through the load balancer to other servers, but mass reconnect is inherently slow. Nothing is lost, because pending notices sit in per-device queues; the cost is delay, and you should say so.
Permissions live in the metadata database, per file or folder: private, shared with a list, or public link. Sharing a folder adds rows and pointers; it never copies chunks. Transport is HTTPS. Chunks are encrypted at the block servers before storage. Google-Docs-style simultaneous editing is out of scope; if asked, name Differential Synchronization or OT as the adjacent hard problem.
One complete design you can study, then rebuild in your own words. Do not recite it. In the interview, draw your graph and defend the choices.
How the graph works: bytes and metadata take different roads. The client chunks a file locally and sends only changed chunks to block servers, which write them to object storage by hash. In parallel, the client commits a new version (a list of hashes) to the sync service, which writes it transactionally and drops a change notice into every other device's queue. Online devices learn through a long poll they already hold, then pull the metadata delta and the missing chunks. Offline devices find the notice waiting when they return. Login, listing, and sharing sit on a separate API service off the hot path.
Web Client (desktop sync app), Mobile Client
+ Note: Watcher, Indexer, Chunker, local metadata DB
→ Load Balancer
→ Service (Block Service: 4 MB chunks, compress, encrypt; mark distributed)
→ Blob Store (S3: chunks keyed by hash; cold tier for old versions)
→ completion callback → Service (Sync Service)
→ Queue (global request queue)
→ Service (Sync Service: version commit, conflict check, fan-out; mark distributed)
→ MySQL (files, versions, chunks, devices, permissions; sharded + replicated)
→ Memcached (metadata cache, invalidate on write)
→ Queue (response queue, one per device; mark distributed)
→ Service (Notification Service: long polling; mark distributed) → other devices
→ Third-party API (APNs / FCM) to wake a sleeping phone
→ Service (API Service: auth, listing, sharing, metadata delta) → MySQL
Components:
Brand-new file, two parallel legs: the metadata leg records pending and other devices hear "upload in progress"; the bytes leg runs chunk by chunk (resumable, retry one chunk on failure); the completion callback flips uploaded and other devices hear "file ready." Parallel for latency; the status gate is what stops a device from fetching a half-uploaded file.
Two people, same file, same instant: both commits claim base version N. The one processed first wins and becomes N+1. The second arrives with base N against latest N+1 and is rejected. That client keeps both copies, its own and the server's, and the person merges. No silent overwrite.
Notification server dies: about a million long polls drop at once. Clients reconnect through the load balancer to other servers. Mass reconnect is slow by nature. Nothing is lost, because pending notices sit in per-device queues; the cost is delay.
Rename or share: metadata only. New path, new permission rows, same chunks. No bytes move.
User(user_id, name, email, created_at)
Device(device_id, user_id, push_id, last_seen_at)
Namespace(namespace_id, owner_user_id)
File(file_id, namespace_id, path, is_directory, latest_version, size, status)
FileVersion(file_id, version, chunk_hashes[], device_id, ts)
Chunk(hash, size, storage_key, ref_count)
Permission(file_id, user_id, role)
Namespace is a user's root folder. Device.push_id is for mobile push. Permission.role is owner, editor, or viewer.FileVersion rows are immutable; history integrity depends on it. Any version rebuilds by joining its chunks in order.FileVersion row plus the File.latest_version update commit in one transaction. File.status is pending or uploaded.file_id (or namespace_id to keep a folder on one shard) with consistent hashing; master plus replicas per shard.Chunk.hash is the key in the Blob Store too; ref_count drives garbage collection once versions age out.WebSocket instead of long polling if you argue the traffic shape. Kafka per-user topics with per-device offsets instead of per-device queues. Postgres instead of MySQL; DynamoDB if you explain where ACID gets rebuilt. Content-defined chunking instead of fixed 4 MB. Client-direct-to-S3 with presigned URLs if you own the platform-logic and encryption trade. Post-process dedup if you value ingest latency over bandwidth. What matters is that you can argue the tradeoff.