What it is
A file storage and sync service stores users' files durably, keeps every device up to date, and lets users share links. Dropbox, Google Drive and OneDrive are the familiar examples. Underneath, two very different systems cooperate: a small, strongly consistent metadata system (files, folders, versions, permissions) and a huge, cheap blob system (the bytes).
Why it exists
Files are large, networks are unreliable, users have several devices, and storage costs real money at scale. Uploading whole files on every change wastes bandwidth; storing every copy wastes disk; letting two devices overwrite each other loses work. The design exists to make uploads resumable and incremental, storage deduplicated, and sync both fast and correct.
How it works
Requirements. Functional: upload, download, delete, rename and move files; versions; sync across devices; shared links. Non-functional: durability above all (no lost files), metadata consistency (no lost updates, no phantom files), sync latency of seconds, efficient use of bandwidth and storage.
Estimates (illustrative). 10 million daily users changing 10 files a day is 100 million changes a day, about 1 200 per second on average and a few thousand at peak. At 1 MB per change that is roughly 100 TB of new data a day before deduplication, so storage growth, not request rate, dominates cost. Metadata requests outnumber byte transfers because every sync check is a metadata read.
Chunking. The client splits each file into chunks (fixed 4 MiB, or content-defined chunking that finds boundaries from the data so inserting a byte does not shift every later chunk) and computes a SHA-256 hash per chunk. A file version is the ordered list of hashes.
Upload flow. The client sends the hash list; the metadata service replies with the hashes it does not have; the client uploads only those; then it commits the version. A failed chunk is retried alone. Object storage multipart uploads (S3, GCS, Azure Blob) provide the same resumability for single large objects.
Presigned URLs. For each missing chunk the API returns a URL signed for one operation on one key, valid for minutes. The client talks to object storage directly; the API never carries bytes. Downloads use presigned GET URLs or signed CDN URLs.
Deduplication. Because chunks are keyed by hash, identical content is stored once: across versions of a file, across files, and optionally across users. Reference counts (or periodic mark-and-sweep over all versions) decide when a chunk can be deleted.
Sync. Every metadata change appends to a per-user change log. Devices hold a long-lived connection (WebSocket, long polling or mobile push) to a notification service that says only "something changed". The device then asks for changes since its cursor, applies them, and fetches missing chunks. A device that was offline catches up the same way.
Conflicts. A commit carries the version it was based on. The metadata service commits only if that is still the current version (compare-and-set). Otherwise the commit is rejected and the client keeps its edit as a conflicted copy. Collaborative editors (Docs, Figma) avoid this with operational transforms or CRDTs, which a generic file service cannot apply to arbitrary binaries.
Downloads at scale. Shared links can be hot. A CDN caches popular files near users; misses go to object storage. Request coalescing at the edge (and an origin shield) keeps concurrent misses for the same object from multiplying.
When to use it
Any product where users bring their own files and expect them everywhere: sync clients, document management, backups, media libraries, collaboration tools with attachments.
When not to
- Only a few uploads per user, no sync: object storage plus a metadata table and presigned URLs is enough; skip chunking and dedup.
- Real-time collaborative documents: model the document as operations, not files.
- Strictly end-to-end-encrypted storage: server-side cross-user dedup is impossible by design.
Trade-offs
| Choice | You gain | You pay |
|---|---|---|
| Small chunks | Better dedup, smaller retries | More metadata rows and requests per file |
| Content-defined chunking | Dedup survives inserts and shifts | CPU on the client, variable chunk sizes |
| Global (cross-user) dedup | Maximum storage savings | Leaks whether a file exists; harder deletion accounting |
| Presigned direct uploads | API not on the data path, cheap scaling | Signing logic, expiry handling, harder server-side validation |
| Strongly consistent metadata store | No lost updates, simple conflict rules | Harder to scale than an eventually consistent store; partition by user or namespace |
Alternatives
- Whole-file uploads to object storage with multipart upload: simpler, fine for media libraries without sync.
- Operation-based sync (CRDTs, OT) for structured documents.
- Peer-to-peer LAN sync between a user's own devices to save bandwidth, with the server still as source of truth for metadata.
Failure modes
- Lost update: last writer wins silently. Prevent with conditional commits.
- Orphan chunks: uploaded but never committed; clean up after a grace period.
- Premature garbage collection: deleting a chunk a pending commit is about to reference. Use grace periods and reference checks inside the commit.
- Missed notifications: harmless if devices always pull by cursor; fatal if the notification itself carries the data.
- Cold CDN cache or viral file: the origin suddenly sees the full download rate. Coalesce misses, add an origin shield, rate-limit per object.
- Hot metadata partition: one huge shared folder concentrates writes on one shard.
In production
Partition metadata by user or namespace; keep the change log append-only with monotonically increasing cursors. Verify chunk hashes server-side after upload. Watch commit conflict rates, sync lag (time from commit to other devices applying it), upload retry rates by network type, CDN hit ratio and origin read rate. Encrypt chunks at rest and decide explicitly on the dedup scope. Set lifecycle rules so old versions move to colder, cheaper storage classes.
Common misconceptions
- "Object storage is the database." It stores bytes well; listing, renaming, permissions and versions belong in a metadata store.
- "Notifications keep devices in sync." They only shorten the delay; the cursor guarantees completeness.
- "Dedup is free savings." It costs metadata, garbage-collection complexity and, at global scope, privacy.
- "A CDN only makes downloads faster." It also hides most of the read load from the origin, which is exactly what you lose when the cache is cold.
Interview angle
Lead with the split: metadata service and database versus object storage, then chunking. Interviewers probe: how a resumed upload works, how dedup is keyed and scoped, how devices learn about changes and catch up after being offline, what happens when two devices edit the same file, how large downloads avoid the API (presigned URLs, CDN), and how you garbage-collect chunks. Estimating storage growth per day and noticing it dominates cost stands out.
Model assumptions
The upload, dedup, presigned-URL, sync and conflict steps are scripted illustrations: packets show who talks to whom and in which order; the engine does not model uploads, hashing, signatures or notification channels. The CDN steps are simulated and simplified, not a benchmark: viewers request 3 000 files with Zipf-distributed popularity (exponent 1.1); the edge cache is an LRU of 300 files; object storage is modelled as a database with 10 connections, about 60 ms per read (lognormal, cv 0.4) and a 200 ms wait limit for a connection, roughly 165 reads per second. Network hops take a fixed 1–40 ms. A restarted cache comes back empty. Coalescing shares one origin read among concurrent misses for the same file on the same edge. Numbers show behaviour and orders of magnitude only.