Design a Multi-Tenant File Sync and Share Platform
System DesignModel answerLast updated
Design an enterprise file storage service covering resumable chunked uploads, metadata/blob separation, versioning, and inherited permissions.
Scenario
You are designing an enterprise document storage and collaboration product (think a hosted drive for companies). End users upload, organize, version, and share files inside deeply nested folder trees. Tenant administrators need fine-grained permissions and a complete audit trail.
Requirements
Functional
- Upload, download, overwrite, and delete files ranging from 1 KB to 10 GB.
- Arbitrary folder hierarchies with rename/move of files and folders, plus tag-based search.
- Version history: every overwrite keeps the prior content, and users can roll back.
- Role-based sharing (Owner / Editor / Viewer) granted at file or folder granularity, inherited down the tree.
Non-functional
- 11 nines of durability for file bytes.
- 99.99% availability for both metadata and blob reads.
- p95 under 50 ms for metadata operations such as listing a directory.
- Large uploads must resume after a network drop without re-sending already-transferred bytes.
Scale
- 50M monthly active users, 10M daily active users.
- 2B files today, +20M files/day, average 2 MB with a tail to 10 GB.
- Metadata read:write ≈ 10:1; blob download:upload ≈ 5:1.
What to Cover
- API design, including the resumable upload handshake.
- Storage architecture: separating metadata from blob storage, chunking, deduplication.
- Data model for the tree, versions, chunks, and permission inheritance.
- Consistency and integrity: concurrent writes, atomic metadata updates, garbage collection.
Hints
Hint 1
Estimate metadata QPS and blob throughput first — they have wildly different shapes and should not share a storage layer.
Hint 2
Make the upload API return the list of chunk hashes the server is missing; that single trick gives you resume and deduplication at once.
Hint 3
For inherited permissions, store the chain of ancestor IDs on each node so a permission check is one indexed query instead of a recursive walk.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
1. Frame the problem and do the math
Open by confirming scope: real-time co-editing is out; desktop/mobile sync clients are just API consumers; tenants are enterprises, so isolation and audit are first-class.
- Write rate: 20M files/day ≈ 230/s average, ~700/s at a 3× peak.
- Ingest: 20M × 2 MB ≈ 40 TB/day logical, ~15 PB/year before versions; the existing corpus is ~4 PB.
- Metadata QPS: 10M DAU × ~100 metadata ops/day ≈ 1B/day ≈ 12K QPS average, 40K+ peak, ~90% reads.
- Metadata size: 2B nodes × ~1 KB plus versions and ACLs ≈ a few TB — fits a sharded relational/NewSQL store.
- Blob reads: ~5× uploads, a few thousand downloads/s, served via CDN or presigned URLs, never proxied through app servers.
The takeaway: metadata is small, hot, and needs strong consistency; blobs are enormous, cold, and need durability. Design them as two independent systems.
2. API design
POST /v1/uploads {parent_id, name, size, chunk_hashes[], base_version_id?}
-> {upload_id, missing_chunks:[{hash, presigned_put_url}]}
PUT <presigned url> # one chunk per request, retryable individually
GET /v1/uploads/{id} -> still-missing chunks (resume)
POST /v1/uploads/{id}/commit -> {node_id, version_id} (409 on stale base_version_id)
GET /v1/files/{node_id}/content?version= -> chunk manifest + presigned GET URLs (Range OK)
GET /v1/folders/{node_id}/children?cursor=&limit=
PATCH /v1/nodes/{node_id} {name?, new_parent_id?} If-Match: <etag>
DELETE /v1/nodes/{node_id} # soft delete to trash
GET /v1/files/{node_id}/versions; POST .../versions/{vid}/restore
PUT /v1/nodes/{node_id}/permissions {principal, role, inherit}
GET /v1/search?q=&tags=
Resumability + dedup in one mechanism: the client chunks and hashes the file up front; the server replies only with the chunks it does not already hold. After a disconnect the client calls GET /uploads/{id} and re-sends only what is missing. Sessions expire after ~7 days.
3. Storage architecture
Metadata service: stateless API nodes over a sharded transactional store (Postgres/Vitess or Spanner/CockroachDB). Shard by tenant_id, so a tenant's whole tree lives on one shard and folder moves/renames are single-shard ACID transactions. Very large tenants get dedicated shards and are split by top-level subtree if needed.
Blob service: content-addressable chunk storage on object storage. Keys are tenant_id/sha256. Erasure coding across three AZs plus cross-region replication gets to 11 nines.
Chunking:
- Fixed 4 MB chunks are simple and easy to parallelize, but one inserted byte shifts every subsequent boundary and destroys dedup.
- Content-defined chunking (Rabin/FastCDC, ~1–8 MB, 4 MB average) keeps boundaries stable across edits and dedups Office documents and re-uploads well.
- Recommendation: CDC for desktop clients, fixed chunks for browser uploads, single chunk for files under ~256 KB.
Dedup scope is per tenant, not global — global dedup leaks a "does this tenant hold file X?" side channel and complicates per-tenant keys and legal deletion.
Supporting services: Elasticsearch fed by CDC for search, Kafka into WORM storage for audit, Redis for effective-ACL caching.
4. Data model
nodes(tenant_id, node_id PK, parent_id, name, type, ancestor_path,
current_version_id, etag, inherit_acl, deleted_at)
UNIQUE(tenant_id, parent_id, name)
versions(version_id PK, node_id, seq, size, sha256_full, author_id,
created_at, storage_class, parent_version_id)
version_chunks(version_id, idx, chunk_hash) -- ordered manifest
chunks(tenant_id, chunk_hash PK, size, refcount)
acl_entries(tenant_id, node_id, principal_id, role, created_by)
upload_sessions(upload_id, node_id, base_version_id, chunk_hashes, expires_at)
Inheritance via materialized path: store /root/a1/b7/ on each node. A permission check becomes one indexed query — SELECT max(role) FROM acl_entries WHERE node_id IN (ancestors ∪ self) AND principal IN (user ∪ groups) — with no recursion; folders marked inherit_acl=false cut the walk. The cost is that moving a folder rewrites ancestor_path across the subtree, which is O(subtree) but acceptable since moves are rare and stay within a shard (run big moves as a background job behind a lock). A closure table avoids the rewrite but costs O(depth × subtree) rows per move.
ACL caching: cache (user, node) -> role keyed with a per-tenant acl_epoch; any ACL change or move bumps the epoch and safely invalidates everything.
Meeting 50 ms p95: a listing is one range scan on (parent_id, name) served from read replicas with cursor pagination.
5. Consistency and integrity
Order of operations: blobs first, metadata last. Chunks are uploaded and SHA-256 verified server-side before commit, so metadata never references a missing chunk. The commit transaction inserts the version + manifest, increments chunks.refcount, performs a compare-and-swap on nodes.current_version_id = base_version_id, and writes an outbox row; a relay publishes to search, audit, and notifications — effectively exactly-once without 2PC across stores.
Concurrency: renames/moves use If-Match etags; a move also rejects cycles by checking the target's ancestor_path doesn't contain the moved node; the unique (parent_id, name) index blocks duplicates.
Garbage collection: orphan chunks come from abandoned uploads and deleted versions. A mark-and-sweep job reclaims refcount=0 chunks after a 7-day grace period (avoids racing an in-flight commit). Trash and legal-hold retention delay the decrement.
Integrity: clients send a full-file hash; background scrubbers re-hash chunks and repair from parity. Metadata is synchronously replicated and backed up.
6. Common mistakes
- Stuffing blobs through app servers instead of presigned direct-to-storage URLs.
- Global dedup that leaks cross-tenant file existence.
- Global
current_versionupdates without CAS, silently losing concurrent writes. - Recursive permission walks that blow the 50 ms budget on deep trees.
- Forgetting that deleting a version must decrement refcounts only after grace periods, or you delete chunks an in-flight commit is about to reference.