Design Dropbox Sync to Avoid Redundant Downloads using chunking and hashing
Difficulty: MEDIUMCategory: HLDFrequency: 1Asked On 2022-01-19
Problem Statement
Designing a Dropbox-like file synchronization system that ensures efficient upload/download, minimal redundant data transfer, and high availability. A key requirement is to avoid redundant downloads/uploads when files are updated by using chunking and hashing techniques.
The system should scale to millions of users, each syncing multiple devices, with files ranging from small text documents to large videos.
Functional Requirements
1.File Synchronization
•Support file upload, download, and sync across multiple devices.
•Automatically sync changes (create, update, delete) in near real-time.
2.Chunking & Hashing
•Break files into fixed-size or variable-size chunks.
•Each chunk should be hashed (SHA-256 or MD5).
•If a chunk already exists on the server, skip re-upload/download.
3.Conflict Handling
•Support concurrent edits → versioning or conflict resolution.
4.Cross-Platform Support
•Work across Windows, Mac, Linux, Mobile.
5.User Features
•File version history.
•Selective sync (choose folders to sync).
•Resume sync on failure.
Non-Functional Requirements
•Scalability: Handle millions of users & billions of files.
•Low Latency: Sync should be near real-time.
•Efficiency: Avoid redundant transfers → only sync modified chunks.
•Reliability: Ensure data is not lost during failures.
•Security: End-to-end encryption for files and chunks.
•High Availability: 99.99% uptime, multi-data center replication.
Design Considerations
1.Chunking Strategy
•Fixed-size (e.g., 4 MB chunks) vs. variable-size (content-defined chunking using Rabin fingerprinting).
•Trade-off: fixed is simpler; variable reduces redundant data when small edits shift file boundaries.
2.Hashing for Deduplication
•Each chunk → hash → check if already exists in storage.
•Maintain a metadata index mapping file → list of chunk hashes.
3.Sync Algorithm
•Client compares local metadata (chunk hashes) with server metadata.
•Upload/download only missing/changed chunks.
•Use delta sync for large files (upload only changed parts).
4.Metadata Store
•Central service storing file metadata:
•User → Files → Versions → Chunk Hashes.
•Needs to support fast lookup and updates.
•Can be stored in distributed NoSQL DB (Cassandra, DynamoDB, etc.).
5.Storage Layer
•Chunks stored in a distributed object store (S3, GCS, HDFS).
•Indexed by hash for deduplication.
6.Conflict Handling & Versioning
•If same file is updated on multiple devices, create multiple versions.
•Allow user to restore older versions.
7.Communication & Real-Time Updates
•Use long polling, WebSockets, or gRPC streaming for instant notifications.
•Background sync worker for periodic checks.