ReviseAlgo Logo
Advanced20 min readReal-world Case Studies

Design Google Drive

Uploading binary delta segments, sync queues, and WebSocket notifications.

What you'll learn

  • Block Segmentation (4MB Chunks)
  • Delta Sync (Upload Only Changed Blocks)
  • Metadata DB (MySQL with ACID)
  • Notification Service (WebSocket / SSE)
  • Version History (Snapshot per Edit)
  • Conflict Resolution

TL;DR

Uploading binary delta segments, sync queues, and WebSocket notifications.

Visual System Topology

Google Drive — Cloud Sync Architecture

Desktop Client splits into 4MB blocks
Block Server SHA-256 dedup
S3 (Block Store) content-addressed
Metadata DB MySQL — ACID
Notification Service WebSocket / SSE
Version History block snapshots
Upload: Client splits file → compute SHA-256 per block → upload ONLY new/changed blocks → update metadata → notify other devices
Sync: Device 2 receives notification → downloads only changed blocks → reassembles file locally

Concept Overview

Google Drive is a cloud file storage and synchronization service for 1B+ users. Its defining challenge: efficiently syncing files across multiple devices using delta sync — uploading only the changed portions of a file rather than the entire file.

Functional Requirements:

  • Upload and download files of any type (up to 5TB)
  • Sync files across multiple devices in real time
  • Share files and folders with per-user permissions (view/comment/edit)
  • Version history (restore previous versions)
  • Search file content
  • Offline access with conflict resolution

Non-Functional Requirements:

  • Strong consistency for file operations (ACID — no data corruption)
  • Delta sync — only upload/download changed portions of files
  • < 100ms for metadata operations
  • Durability: S3-class eleven-nines data durability
  • Support collaboration (multiple users editing simultaneously)

Capacity Estimation (1B users, 200M DAU):

  • Average storage per user: 15GB free → 15 Exabytes total
  • Active storage: 200M DAU × 100MB active files = 20 Petabytes active
  • File operations: 200M × 10 ops/day = 2B/day = 23K ops/sec
  • Upload bandwidth: 200M DAU × 10MB avg uploads/day = 2 Petabytes/day
  • Block storage: 4MB blocks → 2PB/day ÷ 4MB = 500M new blocks/day

Key Architectural Pillars

1

Block Segmentation (4MB Chunks)

Files are split into fixed-size 4MB blocks on the client. Each block is hashed with SHA-256 — this hash is the block's globally unique identifier. When a file is modified, only the changed blocks have new hashes. The Block Server checks which block hashes already exist in S3. Only NEW blocks (never-seen-before hashes) are uploaded. This is content-addressed storage — identical blocks across different files share the same S3 object.

Example: 1 GB file = 256 blocks of 4MB. User edits a paragraph → 1 block changes. Upload: only 4MB transferred (not 1GB). Content deduplication: if two users upload the same photo, only one copy stored in S3 (same SHA-256 hash). Google Drive saves ~40% storage via deduplication.
2

Delta Sync (Upload Only Changed Blocks)

The sync process on each file save: (1) Client computes SHA-256 for each 4MB block of the modified file, (2) Compares against stored block hashes from last sync (saved locally), (3) Sends only the list of block hashes to the Metadata Service, (4) Metadata Service returns which hashes are NOT in S3 (new blocks that need uploading), (5) Client uploads ONLY those new blocks. For a 1GB file where only one paragraph changed: only 4MB is uploaded instead of 1GB. This is the core bandwidth savings.

Example: Large Photoshop file (500MB): 125 blocks. User adds a layer → changes 3 blocks. Delta sync uploads 12MB (3 × 4MB) instead of 500MB. At scale: 200M DAU saving 97%+ of upload bandwidth vs naive full-file sync = ~100x bandwidth reduction.
3

Metadata DB (MySQL with ACID)

File metadata — file name, owner, permissions, parent folder, list of block hashes in order, version history, created/modified timestamps — is stored in MySQL with full ACID transactions. Why SQL (not NoSQL)? Because file system operations require strong consistency: moving a file, sharing permissions, and version creation must be atomic. A partial metadata update (file moved but permissions not updated) would be catastrophic. MySQL is sharded by user_id.

Example: File record in MySQL: {file_id, user_id, parent_folder_id, name, size, version, block_ids: [sha1, sha2, sha3...], created_at, modified_at}. Transaction: rename file + update parent folder modified_at → must be atomic. NoSQL eventual consistency would allow split-brain file system states.
4

Notification Service (WebSocket / SSE)

When User A modifies a file shared with User B (and B has Drive open on their laptop), B's Drive client needs to know immediately to download the new blocks. The Notification Service maintains a WebSocket/SSE connection to each active Drive client. When the Metadata DB is updated (new file version), a notification event is published to Kafka, consumed by the Notification Service, and pushed to all subscribed devices of affected users.

Example: User A edits shared Google Doc on laptop → Metadata DB updated → Kafka event → Notification Service → WebSocket push to User B's phone → B's Drive app downloads changed blocks in background → B opens file and sees A's latest version within 2 seconds.
5

Version History (Snapshot per Edit)

Every time a file is saved, a new version record is created in MySQL linking to the current list of block hashes. Old versions are NOT deleted immediately — they're retained for 30 days (or forever for paid plans). Because blocks are content-addressed and shared across versions, version history doesn't multiply storage: if a 1GB file has 100 versions and only 1 block changed each time, storage is 1GB + 100 × 4MB = ~1.4GB (not 100GB).

Example: Version history for 500MB file, 10 versions, 1 block changed per version: 500MB + 9 × 4MB = 536MB total storage. Restoring version 5: no new upload needed — just update MySQL version pointer to point to the block hash list from version 5. S3 blocks are immutable and reused.
6

Conflict Resolution

When two devices modify the same file simultaneously (Device A offline, Device B online), both have valid changes. Google Drive uses a last-writer-wins with conflict copy strategy: (1) First modification to sync wins and becomes the current version, (2) The losing modification is saved as a separate "conflicted copy" file (e.g., "file (conflicted copy 2024-01-15).docx"), (3) User sees both files and must manually merge. For Google Docs (collaborative editing), Operational Transform (OT) or CRDT enables real-time concurrent editing without conflicts.

Example: Device A edits report.docx offline. Device B edits the same file online and syncs. A comes back online — its edit conflicts with B's version. Result: "report.docx" (B's version, current) and "report (conflicted copy).docx" (A's version). User merges manually or discards one.

AI Tutor

Ask about the topic

Sign in Required

Please sign in to use the AI tutor

Sign In
Design Google Drive - Module 10: Real-world Case Studies | System Design | Revise Algo