Design Google Drive: Block Chunking, Delta Sync, Deduplication & Conflict Resolution
Why Naive Full-File Uploads Fail Cloud Sync
Google Drive Cloud Sync Architecture
1. Client-Side Block Chunking, Compression & Delta Sync
- Chunking (4 MB Blocks): Split the file into ~4 MB chunks (or use Rabin fingerprinting / content-defined chunking so insertions at the start of a file don't invalidate all later chunks).
- Cryptographic Fingerprinting: Compute a
SHA-256hash per block. - Compression: Compress blocks with Zstd or Gzip before transit (text/docs shrink 60%+; skip already-compressed
.jpg/.mp4). - Delta Sync: Client sends block hashes to the API server; only chunks whose hashes don't already exist in S3 are uploaded!
Global Deduplication Savings
2. Two Separate Control Planes: Block Servers vs. Metadata DB
Desktop Client ──(HTTPS Chunks)──► Block Servers ──► S3 Object Storage (Multi-Region)
│
└──(ACID Commits + Sync)──► Metadata API ──► Relational Metadata DB + Cache
│
└──► Notification Service (Long Polling)
Why Metadata Requires Strong ACID Consistency
workspace -> folder -> file_version -> [block_hash_1, block_hash_2]) cannot tolerate stale phantom reads when multiple devices edit concurrently. Use a sharded ACID relational database (MySQL/PostgreSQL) storing:workspaces,files,file_versions(ordered list of block IDs), anddevices.
3. Handling Concurrent Edits & Conflicts
notes.txt offline on an airplane and both reconnect:- Device A commits
version = 5(succeeds via optimistic version checkWHERE latest_version = 4). - Device B attempts to commit
version = 5based onversion = 4→ Optimistic Lock Failure. - Instead of silently overwriting Alice's work, Device B preserves both versions: saving Bob's copy as
notes (Conflict Copy - Bob).txtor prompting a manual merge.