Build a Cloud Storage System with Chunked Uploads and Permissions
System DesignModel answerLast updated
Architect a file-hosting platform separating content from metadata, supporting granular access rules and resumable multi-part uploads.
You're building a cloud storage platform similar to modern file-hosting services. Users need to upload files of any size, share them selectively, and download them reliably. Your architecture must handle interrupted uploads gracefully and enforce fine-grained access control.
Requirements
- Users authenticate and manage their own files
- Files may be arbitrarily large; network interruptions during upload should allow resuming from the last successful piece rather than restarting
- Owners can grant or revoke access to specific users
- The system should prevent incomplete or corrupted files from appearing in user listings
Design Considerations
Think through these architectural questions as you design:
- How do you represent files independently from their stored bytes?
- Where and when do you verify upload permissions versus download permissions?
- What identifier strategy prevents collisions when a file is overwritten?
- How do you ensure only complete, validated files become visible to users?
What to Design
Section A — Storage Schema and Authorization
Propose data models for file records, content storage, and permission rules. Explain how you check authorization when a user lists their files, shares a file, or initiates a download.
Section B — Multi-Part Upload Flow
Detail the lifecycle of uploading a large file in pieces: session initialization, transferring individual segments with retry support, and finalizing the upload. Address orphaned temporary data.
Section C — Download Path and Consistency
Describe how an authorized user retrieves file content. Explain how you handle scenarios where blob storage succeeds but metadata updates fail, or vice versa.
Hints
Hint 1
Consider separating the file record users see from the immutable blob where bytes live—this lets you handle versions and atomic visibility transitions
Hint 2
For chunked uploads, track which segments have arrived successfully so clients can skip them on retry; a manifest listing all chunks enables validation before marking the file complete
Hint 3
Authorization should gate both metadata operations and blob access; signed URLs or short-lived tokens let clients read blobs without embedding permanent credentials
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Model Answer
A strong design separates logical file entities from physical storage, uses explicit permission checks at each boundary, and ensures partial uploads never appear as finished files.
Section A: Storage Schema and Authorization
Data Models
File Metadata Table (SQL or document store):
file_id(UUID): stable identifier across versionsversion_id(UUID): unique per content revisionowner_user_id: creatorname,size,mime_type,created_at,updated_atblob_key: reference to object storage locationchecksum: SHA-256 of complete contentstate:uploading|active|deleted
Access Control List (ACL):
file_id,user_id,permission(read | write)- Index on
(user_id, file_id)for fast lookups
Blob Storage (S3, GCS, Azure Blob):
- Store immutable objects keyed by content hash or version ID
- Separate namespace for in-progress uploads:
temp/{upload_session_id}/chunk_{n}
Authorization Flow
Listing: Query files where owner_user_id = current_user OR ACL entry exists, filtering state = active.
Sharing: Verify requester owns the file (owner_user_id), then insert ACL row. Return success only after database commit.
Download:
- Check ACL or ownership in metadata database
- If authorized, generate a signed URL valid for 15 minutes pointing to
blob_key - Client retrieves bytes using that URL; blob storage validates the signature
This separates authorization logic (metadata tier) from bandwidth (blob tier) and prevents leaking storage keys.
Section B: Multi-Part Upload Flow
Upload Session Initialization
Client calls POST /files/upload-session:
- Server checks write permission (owner or ACL write grant)
- Creates
upload_session_id(UUID) - Returns session ID and suggested chunk size (5-10 MB)
- Stores session record:
{file_id, user_id, created_at, expected_size, chunks_received: []}
Chunk Transfer
Client uploads each piece: PUT /upload-sessions/{session_id}/chunks/{chunk_index} with Content-MD5 header.
Server:
- Validates session not expired (24-hour TTL)
- Writes chunk to
temp/{session_id}/chunk_{index}in blob storage - Verifies MD5 matches header
- Records
chunk_indexinchunks_receivedarray (idempotent: duplicate chunk uploads overwrite and return 200)
On retry after network failure, client requests GET /upload-sessions/{session_id}/status, receives list of completed chunks, and resumes from the next missing index.
Finalization
Client calls POST /upload-sessions/{session_id}/complete with total chunk count and overall checksum.
Server:
- Verifies all chunks 0..N-1 are present
- Assembles chunks into final blob at
blobs/{version_id}(streaming concat or multipart complete API) - Computes checksum, validates against client-provided value
- Atomically updates file metadata: sets
blob_key = blobs/{version_id},state = active,version_id = new_uuid() - Deletes temp chunks asynchronously
- Returns
file_idandversion_id
Critical: File becomes visible only after metadata transaction commits. Partial uploads remain in uploading state and never appear in listings.
Cleanup
Background job runs hourly:
- Delete upload sessions older than 24 hours
- Remove associated temp chunks from blob storage
- Prevent unbounded growth from abandoned uploads
Section C: Download Path and Consistency
Authorized Retrieval
User calls GET /files/{file_id}/download:
- Fetch metadata where
file_idmatches andstate = active - Check ACL or ownership
- If authorized, generate signed URL for
blob_keywith 15-minute expiration - Return HTTP 302 redirect or JSON response with signed URL
- Client fetches bytes directly from blob storage
Range requests: Signed URLs support HTTP Range headers, enabling partial downloads and streaming without proxy overhead.
Failure Scenarios
Blob write succeeds, metadata update fails:
- File remains in
uploadingstate; not visible to users - Background reconciliation job (runs daily) identifies blobs referenced by stale upload sessions and deletes them after 48 hours
- Client sees upload failure, can retry with a new session
Metadata commit succeeds, blob write fails:
- Unlikely with modern object storage (write-then-commit pattern)
- If metadata points to nonexistent blob, download returns 404
- Health check job detects missing blobs, marks file
state = corrupted, notifies owner
Access revoked during download:
- Signed URL remains valid until expiration (15 min)
- Trade-off: shorter expiration improves security, but breaks large downloads over slow connections
- For high-security use cases, proxy downloads through application tier with streaming authorization checks
Garbage Collection
Weekly job scans blob storage for objects not referenced in any active file metadata:
- Objects older than 7 days with no references: delete
- Grace period handles eventual consistency and in-flight transactions
- Prevents storage leaks from failed finalizations
Key Trade-Offs and Extensions
Scale:
- Metadata on PostgreSQL with read replicas handles millions of files; shard by
owner_user_idfor billions - Blob storage scales horizontally; CDN (CloudFront, Cloudflare) for download acceleration
Consistency:
- Strong consistency for ACL checks (read-after-write in metadata DB)
- Eventual consistency tolerable for blob propagation with versioned keys
Versioning:
- Each overwrite creates new
version_id; keep old blobs for history or replace in-place - History requires blob reference counting before deletion
Common Mistakes:
- Exposing blob storage keys to clients (security risk)
- Checking permissions only at upload start, not at finalization (TOCTOU vulnerability)
- Treating upload completion as synchronous without idempotency (duplicate chunks create inconsistency)
- No cleanup strategy for abandoned chunks (cost leakage)
This architecture balances simplicity, security, and fault tolerance for a production file storage service.