TOUGH TONGUE AI
  • Home
    LogoTOUGH TONGUE AI

    RESOURCES

    Loading...

    HomeLibrarySD Mock · Design Dropbox

    SD Mock · Design Dropbox

    Overview

    Design a cloud file storage and sync service like Dropbox or Google Drive on a live architecture board — drag components, wire them up, and defend your design to an expert interviewer who watches every move.

    Your Instructions

    Design a file storage and sync service like Dropbox

    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):

    • Notepad. Shared notes. Requirements, capacity math, schema, and end-of-session feedback live here. You can type in it too.
    • Architecture board. Your design canvas. Drag typed components, wire them, label edges, mark scaled tiers as distributed. If it is not on the board, it is not in your design.

    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."

    Design choices interviewers probe

    Read this before you go in. These are the decisions, and why they matter.

    Chunks, not files

    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.

    The client is part of the distributed system

    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:

    1. Watcher. Monitors the sync folder for create, modify, delete. Also receives remote-change notices.
    2. Chunker. Splits and reassembles files, hashes chunks, works out which ones changed.
    3. Indexer. Applies Watcher events to the local database and drives the commit: chunks to the block servers, the new version to the sync service.
    4. Local metadata DB. Files, chunks, hashes, versions, on disk. This is what makes offline editing possible: edits land locally and sync later. It also saves a metadata round-trip per file.

    Client etiquette: exponential backoff against busy servers; mobile syncs on demand to save battery and data; desktop syncs eagerly.

    Two planes: metadata and bytes

    Never route file bytes through the servers that handle folder trees. Two planes:

    • Byte plane. Client → Block Service (chunk, compress, encrypt) → Blob Store (S3), keyed by content hash. Dumb, durable, horizontally scalable.
    • Metadata plane. Client → Sync Service → MySQL: files, versions, chunk lists, devices, sharing permissions. This is the brain. It must be consistent.

    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.

    Consistency and conflicts

    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.

    How other devices find out

    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.

    Storage economics

    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.

    • Dedup. Same hash, same chunk, store once. In-line dedup hashes at ingest and stores only a metadata reference on a match, so it saves network and storage. Post-process dedup stores first and cleans later, which keeps ingest fast but wastes bandwidth and temporary storage. In-line is the better fit here because the client already computed the hash.
    • Version limits. A hot spreadsheet does not need 1,000 revisions kept forever. Cap versions per file, drop the oldest, weight recent versions as more valuable.
    • Cold storage. Chunks referenced only by months-old versions move to a cold tier (S3 Glacier) at a fraction of the price.

    Capacity (why the shape is unusual)

    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.

    • 500M users × 200 files × 100 KB ≈ 100B files, 10 PB
    • 100M DAU × 2 uploads/day ≈ 200M/day ≈ 2.3K uploads/sec (peak 2×); at ~100 KB each ≈ 20 TB/day of new bytes before dedup and compression
    • 100M DAU × 3 devices; assume ~100M hold an open long poll at once; ~1M connections per server (Dropbox's 2012 number) → ~100 notification servers, plan 2× for headroom
    • 100B files × ~500 bytes of metadata ≈ 50 TB of metadata alone, so the relational store shards
    • Read:write is about 1:1. Every upload is downloaded by the user's other devices. Do not build a read-optimized design out of habit.

    Failure

    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.

    Sharing and security

    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.

    Reference solution

    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.

    Requirements (lock these or take the defaults)

    • Upload and download files of any type, up to 10 GB, from desktop, mobile, and web
    • Automatic sync across all of a user's devices (assume 3 per user)
    • Share files and folders with other users; per-file permissions
    • Offline editing: add, modify, delete while offline; sync on reconnect
    • Version history, bounded
    • Notifications on edit, delete, share
    • Files encrypted at rest; HTTPS in transit
    • Reliability first: data loss is unacceptable. Then fast sync, minimal bandwidth, high availability
    • ~500M users, ~100M DAU
    • Out of scope: real-time collaborative editing (Google Docs)

    Capacity

    • 500M users × 200 files × 100 KB ≈ 100B files, 10 PB total
    • 100M DAU × 2 uploads/day ≈ 200M/day ÷ 86,400 ≈ 2.3K uploads/sec, peak ~5K; ≈ 20 TB/day of new bytes before dedup
    • 2 GB file ÷ 4 MB = 512 chunks; a one-line edit ships 1 chunk (4 MB), not 2 GB
    • ~100M concurrent long polls ÷ ~1M per server ≈ ~100 notification servers (plan ~200)
    • Read:write ≈ 1:1. State-heavy, throughput-light.

    Components to put on the board

    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:

    • Clients (Web = desktop sync app or browser, Mobile). More than uploaders. Watcher, Chunker, Indexer, and a local metadata DB live here; put them in a Note. The local DB is what makes offline editing work and saves a metadata round-trip per file.
    • Load balancer. Spreads clients across block servers, sync servers, and notification servers. Heartbeat fail-over to a secondary. Round robin first, load-aware later.
    • Block Service (mark distributed). Receives only the changed chunks, compresses by file type, encrypts, writes to the Blob Store by hash, and skips the write when the hash already exists (in-line dedup). Reports completion to the Sync Service so status can flip from pending to uploaded. Stateless; a dead block server's in-flight chunks are retried elsewhere.
    • Blob Store (S3, plus a cold tier). Durable chunk bytes keyed by SHA-256. Same-region and cross-region replication. Months-old versions move to Glacier-class storage. It never knows about folders or filenames.
    • Global request Queue (optional). All client metadata updates enter here; many Sync Service instances consume. Smooths bursts and load-balances for free.
    • Sync Service (mark distributed). The brain of one edit: check the base version against the database, write an immutable version row and move the file's latest pointer in one transaction, invalidate the cache, then fan out a change notice into each other device's queue. Conflict detection happens here.
    • MySQL (metadata, sharded and replicated). Users, devices, namespaces, files, versions, chunk lists, permissions. Relational because the version commit needs ACID. Shard by hash of file id with consistent hashing; master plus replicas per shard, promote on failure.
    • Memcached (metadata cache). Hot folder listings and file rows. Invalidate on every write; a stale entry here shows two devices two different trees. A second Memcached for hot chunks is a wrap-up topic (a 144 GB box holds ~36K chunks, LRU).
    • Response Queues, one per device (mark distributed). A queue deletes a message once read, so one queue cannot broadcast. Per-device queues are forced by that semantic, and they give you offline sync: the notice waits until the device is back.
    • Notification Service (long polling, mark distributed). Holds one long poll per online device, about a million per server. When a device's queue has a message, the server answers the poll. The device closes it, pulls the metadata delta from the API Service, downloads missing chunks, re-opens a poll.
    • Third-party push (APNs / FCM). Wakes a sleeping phone so it can sync on demand. The change notice is already in the queue; push is a hint, not the message.
    • API Service. Login, profile, folder listing, revision history, share management, and the metadata delta a device fetches after a notification. Stateless, off the hot path.

    Walk one edit: laptop fixes a typo in a 2 GB project file, phone picks it up

    1. The Watcher on the laptop sees the save. The Chunker re-hashes the file: 512 chunks of 4 MB, SHA-256 each. Against the local metadata DB, exactly one hash is new.
    2. The client sends that one chunk to the Block Service through the load balancer. The Block Service compresses it, encrypts it, and writes it to the Blob Store under its hash. If that hash already exists (another user, another file), it writes nothing and references it.
    3. In parallel, the Indexer commits metadata to the Sync Service: version N+1 = the same 511 hashes plus 1 new one, base version N, status pending. The Sync Service checks that N is still the latest. It is, so it writes the immutable version row and moves the file's latest pointer in one transaction, and invalidates the cache entry.
    4. The Block Service reports completion; status flips to uploaded. The laptop gets its ack only now. Persist before you ack.
    5. The Sync Service drops a change notice into the response queue of every other device on this file: the user's phone, and the laptop of anyone the folder is shared with.
    6. The phone holds a long poll on a Notification Server. The server answers "changes available." The phone closes the poll, asks the API Service for the metadata delta, sees one hash it does not have, downloads that one chunk from the Block Service, decrypts and decompresses it, rebuilds the file, updates its local DB, and re-opens the poll.
    7. If the phone is asleep, APNs or FCM wakes it and it syncs on demand. If it is off, the notice waits in its queue and step 6 runs on reconnect.

    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.

    Schema

    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.
    • New FileVersion row plus the File.latest_version update commit in one transaction. File.status is pending or uploaded.
    • Shard metadata by hash of 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.

    Scaling and wrap-up

    • Block Service, Sync Service, and Notification Service scale horizontally behind the load balancer; the Blob Store scales on its own
    • The metadata database breaks first at 10×: shard by file id hash, add replicas, keep the cache invalidate-on-write
    • Per-device queues scale by count; the Notification fleet scales by connections (10× DAU ≈ 1,000 servers)
    • Dedup, version caps, and cold storage are where the money is saved
    • First metrics: time-to-sync across devices, upload bytes ÷ file bytes (delta efficiency), conflict rate, long-poll reconnect storms
    • If time: block cache, direct-to-S3 trade-off, presence service split out of notifications, malware scanning of uploads, garbage collection of unreferenced chunks

    Equally defensible variants

    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.

    More in System Design Interview Prep: AI Coach Edition

    • SD Mock · Design a Notification System
    • SD Coach · Async Jobs, Schedulers and Crawlers
    • SD Mock · Design a Web Crawler
    • SD Coach · Distributed Storage
    • SD Mock · Design a Key-Value Store
    • SD Coach · File Sync: Dropbox and Google Drive
    • SD Coach · Transactional Systems
    • SD Mock · Design Ticketmaster
    • SD Coach · Batch and Stream Pipelines
    • SD Coach · Real-Time Chat and Collaboration
    • SD Mock · Design Facebook Messenger
    • SD Mock · Design Uber Backend
    View the full course (43 sessions) →