Design Google Drive
Understanding the Problem
📁 What is Google Drive? Google Drive is a cloud file store. Users upload files and folders, open them from any device, share them with other people, and roll back to older versions. With the desktop app installed, a folder on your laptop mirrors your Drive: change a file on one machine and it appears on your other machines a few seconds later.
You'll also be asked to "design Dropbox." It's the same problem. Dropbox is known for its desktop sync client and Drive for its web app, but both are a metadata service, a blob store and a sync protocol. We'll cover web upload and download, desktop sync, sharing, versions and deduplication, which together are what both questions are after.
Functional Requirements
Core Requirements
- Users should be able to upload a file, including very large ones (up to 50 GB).
- Users should be able to download a file from any device.
- Users should be able to share a file or folder with other users, as viewers or editors.
- Users should have their files synced automatically across all their devices.
We'll also cover keeping version history and restoring an old version, which falls out of how we store files.
Below the line (out of scope)
- Real-time co-editing of documents (that's
/system-design/google-docs). - Full-text search inside files, previews and thumbnails.
- Storage quotas and billing.
Non-Functional Requirements
Ask about scale. For our design: 500M registered users, 100M daily active, an average of a few GB stored per user, and files from a few bytes up to 50 GB.
Core Requirements
- Files must be extremely durable. Losing a user's file is the worst thing this system can do.
- Uploads and downloads should be as fast as the user's connection allows, and large uploads must resume after a network failure instead of starting over.
- A change on one device should show up on the user's other devices within seconds.
- The system should be highly available for reads. If the metadata service is briefly degraded, users should still be able to download files they can see.
- Metadata updates must not silently lose edits. If two devices change the same file, we must not throw one away.
Below the line (out of scope)
- Compliance features like legal hold, data residency and malware scanning.
Back of the envelope. If each daily user changes 5 files a day, that's 500M uploads per day, about 6,000 per second on average and maybe 15,000 per second at peak. At an average of 1 MB that's around 500 TB of new data per day before deduplication. Stored data is the bigger number: 500M users × a couple of GB is on the order of 1 exabyte.
Two conclusions follow. First, file bytes must never flow through our application servers; at hundreds of terabytes a day, clients should talk to blob storage directly. Second, at exabyte scale, not storing the same bytes twice saves real money, which is why deduplication is in scope.
The design splits cleanly into two very different systems: a metadata service (file names, folders, versions, permissions, change logs) that is small, transactional and queried constantly, and a blob store that is enormous, immutable and dumb. Say this early. Most of the interesting decisions are about keeping them in step.
The Set Up
Planning the Approach
We'll do upload, download, sharing and sync in that order, starting simple. The deep dives cover large and resumable uploads, deduplication, fast sync with conflict handling, and versioning.
Defining the Core Entities
- File: a node in a user's tree: ID, name, parent folder ID, owner, current version, size, and whether it's a folder.
- FileVersion: an immutable snapshot of a file's content: version ID, size, author, time and the ordered list of chunk hashes that make it up.
- Chunk: a piece of file content (a few MB), stored once in the blob store and addressed by the hash of its bytes.
- Share: a grant on a file or folder: which user or group, and which role (viewer, commenter, editor).
- Change: one entry in a user's change journal ("file 9 renamed," "file 12 got version 4"), with an increasing sequence number. This is what devices sync from.
API or System Interface
POST /files/uploads { name, parentId, size, chunkHashes: [...] }
-> { uploadId, missingChunks: [{ hash, uploadUrl }] } // presigned URLs
POST /files/uploads/{uploadId}/commit
-> { fileId, versionId }
GET /files/{fileId} -> { name, size, versionId, chunks: [{ hash, downloadUrl }] }
GET /files/{fileId}/versions -> [{ versionId, author, time, size }]
POST /files/{fileId}/versions/{versionId}/restore -> { versionId }
POST /files/{fileId}/shares { principal, role }
GET /changes?cursor={cursor} -> { changes: [...], cursor, hasMore }
The user's identity always comes from the auth token. Download and upload URLs are short-lived presigned URLs, so the blob store can serve bytes directly without trusting the client with credentials.
High-Level Design
1) Users should be able to upload a file
The first version most people draw: the client POSTs the file to a File Service, which writes it to S3 and inserts a row in a metadata database. That works for a 2 MB PDF. For a 20 GB video it means our servers hold a 20 GB request body open, every byte crosses our network twice, and a dropped connection at 19 GB starts the whole thing over.
So we take our servers out of the data path. The client asks the File Service for an upload, the service creates the metadata row in an uploading state and returns a presigned URL for S3. The client uploads directly to S3, and when it's done it calls commit. The File Service checks that the object exists and has the expected size and checksum, then marks the file available. As a safety net, S3 event notifications can also trigger the commit, in case the client disappears after uploading.
For metadata we'll use Postgres to start: files, versions and shares are relational, and we need transactions when we commit a new version and update the parent folder at the same time. We'll shard it later.
2) Users should be able to download a file
Download is the mirror image. The client asks the File Service for a file; the service checks permissions, looks up the current version and returns presigned GET URLs. The client downloads straight from S3, or from a CDN in front of it for popular shared files, using signed CDN URLs that expire in minutes. For large files, the client fetches pieces in parallel with HTTP range requests, which also lets it resume an interrupted download.
3) Users should be able to share files and folders
Sharing is a metadata problem. A Shares table holds (file_id, principal, role). Sharing a folder means everything under it is shared, so when Bob opens a file, the permission check walks up the folder chain until it finds a grant for Bob or reaches the root:
WITH RECURSIVE ancestors AS (
SELECT id, parent_id FROM files WHERE id = :fileId
UNION ALL
SELECT f.id, f.parent_id FROM files f JOIN ancestors a ON f.id = a.parent_id
)
SELECT role FROM shares
WHERE file_id IN (SELECT id FROM ancestors) AND principal IN (:bobId, :bobGroupIds);
Folder trees are rarely more than 10–20 levels deep, so this is a handful of indexed lookups, and it's cached per user and folder. "Shared with me" is an index on shares(principal). Link sharing ("anyone with the link can view") is a share whose principal is a random unguessable token.
At larger scale, permission checks usually move into a dedicated authorization service built on relationship tuples, which handles inheritance and groups much more efficiently (see /system-design/authorization-service).
4) Files should sync automatically across devices
The desktop client watches the sync folder for local changes (FSEvents on macOS, ReadDirectoryChangesW on Windows, inotify on Linux) and uploads anything that changes, using the upload flow above.
The other direction is the interesting part: how does your laptop find out that your phone uploaded something? Every metadata change writes a row to a change journal for each affected user, with an increasing sequence number. Each device remembers the last sequence it processed (its cursor) and asks for everything after it: GET /changes?cursor=8812. The response is a list of creates, renames, moves, deletes and new versions, plus a new cursor. The device applies them locally: download new versions, rename files, and so on.
This is much better than comparing full folder listings: a device that's been asleep for a day asks for one day of changes, not a scan of 200,000 files. How the device knows when to ask is deep dive 3.
Potential Deep Dives
1) How do we upload large files reliably and efficiently?
A 50 GB upload on a home connection takes hours. It will be interrupted. And when a user edits a 2 GB file, re-uploading all 2 GB for a one-byte change is wasteful.
Bad Solution: One Big PUT
Approach
Upload the whole file in a single request to the presigned URL.
Challenges
Any network blip means starting over. S3 also caps a single PUT at 5 GB. There's no parallelism, and no way to report accurate progress or resume after the laptop sleeps.
Good Solution: Fixed-Size Chunks with Multipart Upload
Approach
Split the file into fixed-size chunks (say 8 MB) and use S3 multipart upload: the File Service starts a multipart upload, hands the client one presigned URL per part, and the client uploads several parts in parallel. The client records which parts finished, so after an interruption it asks the server which parts it already has and uploads only the rest. On commit, S3 assembles the parts.
Challenges
It solves resumability and parallelism, but editing a file still re-uploads all of it, since the multipart object is one blob. And with fixed offsets, inserting a single byte near the start of a file shifts every chunk boundary after it, so every chunk changes.
Great Solution: Content-Defined Chunks, Uploaded Only If Missing
Approach
Make chunks the unit of storage, not just the unit of transfer. The client splits the file using content-defined chunking: it slides a rolling hash (Rabin fingerprint or similar) over the bytes and cuts a chunk wherever the hash matches a pattern, aiming for an average of a few MB. Boundaries depend on content, not offset, so inserting a byte only changes the chunk it lands in; every chunk after it re-synchronizes to the same boundaries.
Each chunk is named by its SHA-256 hash and stored in the blob store under that hash. A file version is just an ordered list of chunk hashes. The upload protocol becomes:
- The client chunks and hashes the file locally, then sends the list of hashes to the File Service.
- The service checks which hashes it already has and returns presigned URLs only for the missing ones.
- The client uploads those chunks, in parallel, each one independently retryable.
- On commit, the service verifies every chunk exists and writes the new version row with the chunk list.
Editing a few paragraphs in a 2 GB file re-uploads one or two chunks. A 50 GB file is about 10,000 chunks of 5 MB, and its hash list is around 320 KB, which is fine to send in one request.
Challenges
Chunking and hashing cost client CPU, so the desktop app does it in the background. Downloads now assemble a file from many chunks, which the client does by fetching chunks in parallel. And the service needs a chunk index (hash → location, size, reference count), which at a few hundred billion chunks is a big key-value table, a good fit for DynamoDB, Bigtable or a sharded MySQL.
2) How do we avoid storing the same bytes twice?
At exabyte scale, duplicates are everywhere: the same installer downloaded by millions, the same photo shared into many folders, a file copied between folders, and every unchanged chunk shared between versions.
Bad Solution: Store Every Upload Separately
Approach
Every upload gets its own object.
Challenges
Simple, and storage grows with every copy and every version. Ten versions of a 1 GB file cost 10 GB.
Good Solution: Whole-File Hashing
Approach
Hash each file; if we already store a file with that hash, point the new metadata row at the existing object.
Challenges
It catches exact copies, but not a file that changed by one byte, and it does nothing for versions of the same file.
Great Solution: Content-Addressed Chunks with Reference Counts
Approach
With content-defined chunks keyed by hash (deep dive 1), dedup is automatic. Two versions of a file share every chunk they have in common. A copy of a file is a new metadata row pointing at the same chunk list, and costs no storage at all. The chunk index tracks a reference count per chunk: incremented when a version that uses it is committed, decremented when a version is deleted. Chunks whose count reaches zero are garbage-collected after a grace period.
Challenges
- Garbage collection races. A chunk at refcount zero might be about to be reused by an upload in progress that saw "we already have it." Use a grace period (only delete chunks that have been at zero for a day or more) and have commit re-check that every chunk still exists.
- Refcounts drift. Bugs and partial failures make counters wrong over time. Run a periodic mark-and-sweep that recomputes them from the version table, and treat it as the authority.
- Privacy. If dedup is global across users, an upload that completes instantly reveals that someone already stores that file, which can leak information (for example, confirming a specific document exists). A common mitigation is to dedup per user or per organization only, or to require the client to prove it holds the content rather than just its hash. Global dedup saves more storage; scoped dedup is safer. Say which one you'd pick and why.
Encryption interacts with dedup too. If each user's files are encrypted with their own key, identical files produce different ciphertexts and can't be deduplicated across users. Server-side encryption with keys the service controls keeps dedup possible; true end-to-end encryption mostly rules it out.
3) How do devices learn about changes quickly, and what happens on conflicts?
The change journal tells a device what changed. It also needs to know when to ask, within a few seconds, without 300M devices hammering the API.
Bad Solution: Poll Frequently
Approach
Every device calls GET /changes every few seconds.
Challenges
Say 300M devices, polling every 5 seconds, is 60M requests per second, almost all of them answering "nothing new." Polling every few minutes cuts the load but breaks the "within seconds" requirement.
Good Solution: Long Polling
Approach
The device makes a request that the server holds open for up to a minute or so, returning as soon as anything changes for that user, or empty at timeout. The device then calls /changes with its cursor. Dropbox's desktop client has long used a notification long-poll like this.
Challenges
Each waiting device holds a connection, so the notification tier needs to handle hundreds of millions of mostly idle connections, which is a well-understood problem with event-driven servers. We need a way for the metadata service to wake the right connections, typically by publishing "user U changed" to a pub/sub channel that notification servers subscribe to.
Great Solution: Push a Nudge, Pull the Changes
Approach
Keep long-poll or a WebSocket for the desktop app, and use mobile push (APNs/FCM) for phones, but in every case the push carries no data: it's just a nudge that says "your journal has new entries." The device always pulls through the same /changes?cursor= API. That keeps one source of truth (the journal), makes missed notifications harmless (the next pull catches up), and lets us coalesce bursts: 1,000 files added to a shared folder send one nudge, not 1,000.
Conflicts. Your laptop was offline and you edited budget.xlsx; meanwhile you edited the same file on your desktop, which already synced. When the laptop comes back, its upload says "new version, based on version 7." The File Service commits with a conditional update:
UPDATE files SET current_version = :newVersion
WHERE id = :fileId AND current_version = :baseVersion; -- 0 rows -> conflict
If someone else got there first, the current version is 8, the update matches nothing, and we have a conflict. For binary files we can't merge, so we keep both: the laptop's version is saved as a new file, budget (conflicted copy from Rui's laptop).xlsx, next to the original. Nothing is lost, and the user decides. Renames and moves use the same check on the file's metadata version.
4) How do we store versions and keep the metadata service scaling?
Versions come almost for free. A version is an immutable row with a chunk list; committing a new version doesn't touch old ones, and thanks to chunk dedup, a version that changed one chunk costs one chunk of storage. A retention policy (for example, versions from the last 30 days, or the last 100) deletes old version rows, which decrements chunk refcounts. Restoring version 3 creates version 9 with version 3's chunk list. It's a new commit, so it syncs to every device like any other change and can itself be undone.
Metadata scale. Hundreds of billions of file rows don't fit in one Postgres instance. The natural shard key is the namespace: each user's personal tree is one namespace, and each shared folder or shared drive is its own namespace that is mounted into members' trees. Everything inside a namespace (files, versions, its change journal) lives on one shard, so moving a file within a folder tree, committing a version and appending to the journal is a single-shard transaction.
That explains how sharing interacts with sync. When a shared folder with 500 members changes, we don't write 500 journal entries; we write one entry to the shared namespace's journal. Each device keeps a cursor per namespace it has mounted and pulls from each. Moving a file between namespaces (from your private folder into a shared one) is the rare cross-shard operation, handled as a copy-then-delete with an idempotent workflow.
If your interviewer asks why not just use a key-value store for metadata: folder moves, version commits with a base-version check, and journal appends all want transactions. A relational store sharded by namespace (or a distributed SQL database like Spanner or CockroachDB) keeps those simple. The chunk index, on the other hand, is a pure key-value lookup and doesn't need SQL.
Final Design
The main flow:
- The desktop client detects a local change, splits the file into content-defined chunks and hashes them.
- The File Service returns presigned URLs for chunks the chunk index doesn't already have; the client uploads those straight to S3, in parallel and resumably.
- On commit, the service verifies the chunks, writes the new version with a base-version check (or creates a conflicted copy), updates chunk refcounts, and appends to the namespace's change journal, all on the namespace's metadata shard.
- The commit publishes a nudge; notification servers wake the long-poll or WebSocket connections of the affected users' other devices, and phones get a silent push.
- Each device pulls
/changeswith its cursor and downloads only the chunks it lacks, from S3 or the CDN through presigned URLs. - Sharing writes grants that permission checks resolve up the folder chain; old versions expire by policy and a garbage collector removes unreferenced chunks after a grace period.
What is Expected at Each Level?
Mid-level
You should separate metadata from file bytes, use presigned URLs so clients upload and download directly from blob storage, and store files, versions and shares in a database. You should get to chunked, resumable uploads with some prompting, and describe a basic way for devices to find out about changes, such as polling.
Senior
You should drive toward content-addressed chunks and explain how they give you resumable uploads, delta sync, cheap versions and dedup at once. Expect to design the change journal with cursors, the nudge-then-pull notification model, and conflict detection with a base-version check that creates conflicted copies. You should handle folder-level permission inheritance and size the system from the numbers.
Staff+
You should go deep on the operational edges: garbage collection races and refcount drift, dedup scope and its privacy implications, encryption versus dedup, sharding metadata by namespace and what that does to shared folders and cross-namespace moves. Expect to discuss durability end to end (checksums at every hop, replication across regions) and to make clear calls about which parts need strong consistency (version commits) and which can be eventually consistent (notifications, listings).