Medium · System Design · Cloud Storage · File Synchronization
Design a single-region backend for a personal cloud drive where users store files and folders that stay synchronized across their laptops and mobile devices. The system must handle a namespace of files and metadata that needs low latency and strong consistency, while the actual file bytes are large, deduplicated, and stored on a separate, throughput-optimized path. A revision commit ties these two paths together by making metadata changes visible and publishing them through an ordered sync stream.
Before diving into the design, you clarify the following points with the interviewer.
You: "Should this system handle scenarios where multiple people edit the same file simultaneously in real-time? Or are we limited to a single user per file, where conflicts only happen when that one user's devices go offline and later sync?"
Interviewer: "We're limited to a single user per file. No real-time co-editing. Conflicts arise exclusively when the same user's disconnected devices produce changes to the same file path."
Takeaway: Excluding real-time co-editing means operational transforms and CRDTs are unnecessary. Conflict resolution simplifies to detecting a write based on a stale revision and creating a visible sibling copy rather than merging byte streams.
You: "If two of the same user's devices edit a file while offline and reconnect, should one version win silently, or must both versions be kept so the user can choose?"
Interviewer: "Both versions must be kept. We cannot silently discard one. The losing commit must produce a visible conflict copy for the user to inspect."
Takeaway: Concurrent offline edits cannot be resolved by picking a winner. The system must preserve both user intents and surface the conflict.
You: "When a device comes back online, how does it learn about missed changes? Does the server push events, or does the device poll using a cursor?"
Interviewer: "Push notifications can act as hints to prompt a sync, but they are not the source of truth. A device must always be able to recover the full ordered history via a cursor-based poll. Push events may be dropped or arrive out of order."
Takeaway: Push provides latency improvement, but correctness relies on a replayable pull path that remains functional regardless of notification delivery.
You: "If a large upload is interrupted halfway, must the user restart from the beginning, or should the system support resuming from the point of interruption?"
Interviewer: "Resumable uploads are a firm requirement. Users on unreliable mobile networks should not have to restart large uploads from scratch."
Takeaway: Large file uploads cannot be all-or-nothing operations. The system needs a resumable write protocol and a way to garbage-collect abandoned partial uploads.
You: "Regarding the folder tree and version history, must all devices see the same state instantly, or is a slight delay between devices acceptable?"
Interviewer: "The folder structure, visible file revisions, and conflict outcomes must be strongly consistent within the primary region. Raw file bytes can be eventually consistent, provided the uploading device still sees its own upload immediately after commit."
Takeaway: User-visible metadata truth requires immediate consistency, while byte propagation can tolerate some lag.
You: "Is server-side deduplication a hard launch requirement or an optimization for later?"
Interviewer: "It's a hard requirement. At our target scale—roughly two hundred petabytes of logical data reduced to sixty petabytes physical—storing every upload as a separate copy is cost-prohibitive. Deduplication is integral to the cost model."
Takeaway: Deduplication is fundamental to the cost structure. When content is shared, deletion must respect shared ownership rather than assuming each upload owns its own bytes.
Architecture overview of the cloud drive system
| Quantity | Value | Rationale |
|---|---|---|
| Daily active users | 10M | Drives sync poll rates and listing load |
| Peak metadata writes | ~20k/s | Determines OLTP capacity and sync fanout |
| Peak metadata reads | ~100k/s | Covers browsing, path resolution, and sync catch-up |
| Average file size | ~4 MB | Informs default chunk size and manifest complexity |
| P99 file size | ~500 MB | Necessitates multipart upload and range-heavy downloads |
| Logical stored bytes | ~200 PB | User-visible footprint |
| Physical stored bytes | ~60 PB | Illustrates why deduplication makes refcounting and GC significant |
Out of Scope