System Design · Design Question
Design Google Drive
Cloud file storage: upload/download, metadata, sync, sharing, and dedupe — without mixing file bytes into the metadata DB.
Concrete example: Editing a Google Doc updates metadata in the database and stores a new revision blob in object storage. Your laptop polls with a change token and downloads only files that changed since last sync.
1. Requirements
Functional
- Upload/download files; folder hierarchy; rename/move.
- Sync across devices; conflict handling when two devices edit offline.
- Share with users/groups; permissions (viewer/editor).
- Version history; large files via chunked upload.
Non-functional
- Durable multi-AZ storage, secure authorization, and reliable offline recovery.
- Scale metadata separately from large byte transfers.
Back-of-envelope
2. API
3. Data model
Content-addressed blobs enable dedupe: same hash → reuse storage. Metadata updates are frequent and small; blobs are immutable.
4. High-level design
5. Upload deep dive
- Client requests session; server checks quota.
- Chunked upload; each chunk checksummed; resumable.
- Complete: assemble or compose object; compute full hash.
- If hash exists → dedupe pointer; else store new blob.
- Commit new file_version + metadata TX; append sync_log.
6. Sync and conflicts
For binary files, creating a conflict copy is safer than silent merge. Collaborative docs need OT/CRDT — call that a different subsystem.
7. Sharing and permissions
- ACL on file/folder; inherit from parent with overrides.
- Check permission on metadata read and on signed URL minting.
- Link sharing: secret token capability URLs.
8. Scaling
- Shard metadata by owner_id / file_id.
- Object store + CDN for hot downloads.
- Block-level sync (rsync-like) for huge files optional optimization.
- Quota service to prevent abuse.
9. Reliability
- Never mark upload complete until blob durable.
- GC unreferenced blobs asynchronously after version delete.
- Multi-AZ object store replication.
10. Client sync protocol sketch
Delta sync reduces bandwidth: only changed blocks for large files when the client speaks a block protocol (optional advanced topic).
11. Preview and search (optional)
- Async workers generate previews (PDF page images, video posters).
- Filename/full-text search via separate index updated from metadata events.
12. Failure modes and edge cases
- Chunk upload repeats → checksum and chunk number make it idempotent.
- Blob stored but metadata commit fails → delayed GC removes the unreferenced blob.
- Permission revoked while a signed URL exists → use short URL expiry for sensitive files.
- Move a folder into its descendant → reject to prevent a hierarchy cycle.
Interview talking points
- Lead with: Separate metadata, immutable blobs, and the device sync log.
- Split metadata DB from content-addressed blob store.
- Chunked resumable uploads; dedupe by hash.
- Versions immutable; current pointer in metadata.
- Sync via change feed/cursor per user.
- Conflicts: keep both copies for binaries.
- Permissions checked before minting download URLs.
- CDN/signed URLs for download path.