Dropbox / File Sync
Keep a folder identical across every device — worked through the TOGAF ADM so chunking, dedup, and conflict handling each land in the right phase.
Dropbox, the ADM way, in 30 seconds
- Why TOGAF here: it forces you to define what a file even is (a list of chunks) before you choose storage or a sync protocol — and that reframing is the whole trick.
- A (Vision): a folder that stays identical across every device, syncing quickly and using minimal bandwidth; principles — bandwidth-thrifty, durable, eventually consistent.
- B (Business): capabilities — upload a file, sync changes to other devices, resolve conflicts, share.
- C (Data/App): a file modeled as an ordered list of chunks; a chunk store; a file→chunk metadata map; per-device sync state.
- D (Technology): split files into chunks, hash each, dedup identical chunks, store chunks in blob storage, keep the file→chunk map in a DB, and sync only changed chunks.
- E–H: ship single-device upload, then multi-device sync, then conflict handling; govern with quotas and retention.
- The lesson: once a file is 'a list of hashed chunks', dedup, delta-sync, and versioning all fall out of the same model.
Like editing a book by swapping pages, not reprinting it
Imagine you keep an identical copy of a long book in two cities. You fix one typo on page 243. The silly way to keep both copies in sync is to reprint the entire book and mail it across the country. The smart way: tear out just page 243, print the one corrected page, and mail that. The other city swaps in the single page and the books match again.
File sync is exactly this. The trick that makes it work is to stop thinking of a file as one solid lump and start thinking of it as a numbered stack of pages (we call them chunks). Now a one-line edit only changes one page, so you only move one page. And if two different books happen to contain the very same page, you can keep a single copy and point both at it. That one reframing — file as a list of pages — is the entire design; everything clever afterward just follows from it.
What makes it hard — the problem before the solution
- Whole-file uploads waste everything. If a file is one blob, a one-character edit re-sends the entire file — ruinous for a 2 GB video with a tiny change.
- Identical content gets stored over and over. The same attachment emailed to a team, or a file copied into ten folders, would be stored ten times unless you can recognize 'these bytes are the same'.
- Two devices can edit the same file at once. Someone edits on a laptop offline while someone else edits on a phone — when both reconnect, you must not silently throw one person's work away.
- Devices must converge, fast, with little data. The system has to tell every other device exactly what changed and let it catch up quickly, without re-downloading things it already has.
Why the ADM fits
File sync feels mechanical — copy bytes, keep them the same everywhere — but the hard parts hide in the definition of 'file'. If a file is one opaque blob, every tiny edit re-uploads the whole thing and two devices editing at once is a disaster. The ADM makes you slow down at Phase C and re-model a file as an ordered list of content-addressed chunks. That one reframing, done before any technology talk, is what makes dedup, delta-sync, and conflict handling in Phase D feel inevitable rather than clever.
Phase A — Architecture Vision
Intent: agree what we're building and the principles that constrain every later choice.
- Vision: a synced folder — drop a file on one device and it appears, identical, on every other device the user owns, quickly and without re-sending data that hasn't changed.
- Stakeholders: users (want fast sync, no lost edits, low data usage), the business (wants storage and bandwidth kept cheap at scale), operators (want conflicts handled predictably).
- Principles (the constraints that cascade): bandwidth-thrifty (never move bytes that haven't changed); durable (a synced file must not be lost); eventually consistent (devices converge, they needn't be identical every millisecond).
Phase B — Business Architecture
Intent: model the business capabilities before any technology talk.
- Value stream: user edits a file on device A → changes upload → the service notifies device B → device B downloads only what changed → folders match.
- Capability 1 — Upload a file / a change: push new or modified content to the service.
- Capability 2 — Sync to other devices: detect what changed and deliver just that to each device.
- Capability 3 — Resolve conflicts: two devices edit the same file offline — decide what happens.
- Capability 4 — Share (optional): give another user access to a file or folder.
Impact: the make-or-break capabilities are sync efficiently and resolve conflicts. Both depend entirely on being able to talk about parts of a file, not the whole file — which is exactly what Phase C sets up.
Phase C — Information Systems Architecture (Data & Application)
Intent: define the data and application architecture — and this is where the key reframing happens.
Data architecture
- A file is an ordered list of chunks: split each file into fixed- or content-defined blocks (e.g. ~4 MB each). This is the central modeling decision.
- Chunks are content-addressed: each chunk's identity is the hash of its bytes, so identical content always has the same ID — the basis for dedup.
- File→chunk metadata map: per file, store the ordered list of chunk hashes plus name, size, version, and timestamps — small structured rows.
- Chunk store: the actual chunk bytes, stored once per unique hash.
- Per-device sync state: what version each device last has, so the service knows what to send. (See SQL vs NoSQL.)
Application architecture
- A client agent on each device that watches the folder, chunks and hashes changed files, and uploads only new chunks.
- A metadata service that owns the file→chunk maps and versions — the source of truth for 'what does this file look like now'.
- A notification path (long-poll or push) so other devices learn about changes quickly, decoupled via a queue so uploads don't block notifications.
Phase D — Technology Architecture (the core)
Intent: choose the concrete technologies that realize Phase C and justify each against the principles. This is where an interviewer spends the time, so we cover every step.
D1 — Estimate the load (sizing drives technology)
# 100M users, say 10M active editing at any time
# Suppose 50M file changes/day
change_per_sec = 50_000_000 / 86_400 # ~580 changes/sec
# Without chunking: avg file 1 MB, every edit re-uploads 1 MB
# -> 580 * 1 MB ~ 580 MB/sec of upload
# With chunked delta-sync: a typical edit touches ~1 chunk (4 MB max,
# but usually only the changed block) -> a fraction of that bandwidth
#
# Dedup win: identical chunks (shared files, duplicate uploads) stored ONCE
# Metadata: file->chunk maps are small rows -> a few TB, trivial next to chunk bytes
#
# Verdict: bandwidth and dedup are the whole game -> chunk + hash + store-once.The numbers make the Phase A principle quantitative: moving whole files wastes enormous bandwidth, while chunk-level delta-sync and dedup cut both bandwidth and storage dramatically. The sizing itself points straight at the chunk model.
D2 — Chunking & hashing
- Split each file into chunks on the client — fixed-size blocks are simple; content-defined chunking survives insertions better (a byte added early doesn't reshuffle every later chunk).
- Hash each chunk (e.g. SHA-256) to get a content address; the hash is the chunk's ID.
- Upload only chunks the server doesn't already have: the client asks 'do you have these hashes?' and sends just the misses — the core of bandwidth-thrifty.
- Reassemble on download by fetching the chunk list from metadata and pulling each chunk in order.
import hashlib
def chunk_and_hash(file_bytes, size=4 * 1024 * 1024): # ~4 MB blocks (D2)
manifest = []
for offset in range(0, len(file_bytes), size):
block = file_bytes[offset:offset + size]
digest = hashlib.sha256(block).hexdigest() # content address = the ID
manifest.append((digest, block))
return manifest # ordered list of (hash, bytes)
def sync_upload(server, manifest):
hashes = [h for h, _ in manifest]
missing = server.which_missing(hashes) # dedup: skip chunks already stored
for h, block in manifest:
if h in missing:
server.put_chunk(h, block) # bandwidth-thrifty: send only misses
server.save_file_map([h for h, _ in manifest]) # ordered hash listWhy chunk the file, and why not just sync whole files?
The obvious design is 'a file is a file — upload it when it changes.' It's simple and it's fine for a demo. But it fails on the two things users notice most: a tiny edit to a huge file re-sends the whole thing (slow and expensive), and the same content stored in many places is stored many times (wasteful). Chunking plus content addressing fixes both at once — you move only the chunks that changed, and you store each unique chunk once. The cost is a little client-side bookkeeping (split, hash, diff), which is cheap and runs on the user's own device.
| Approach | What it buys | The gap it can't fill |
|---|---|---|
| Whole-file sync | Dead simple; no chunk bookkeeping. | A one-byte edit re-sends the whole file; identical content stored repeatedly — bandwidth and storage both blow up. |
| Fixed-size chunks | Simple splitting; enables delta-sync and dedup. | Inserting bytes early shifts every later boundary, so one insert can look like 'everything changed'. |
| Content-defined chunks (chosen for edits) | Boundaries follow content, so an insert only changes nearby chunks; best dedup. | More complex to compute — worth it for files that get edited in the middle. |
D3 — Dedup & the chunk store
- Store each unique chunk once, keyed by its hash, in object/blob storage (e.g. S3-style) — cheap, durable, effectively unbounded.
- Dedup falls out for free: two users uploading the same file, or one file copied many times, share the same chunks because identical bytes hash identically.
- Reference-count or garbage-collect chunks so a chunk is only deleted when no file version points to it.
- Replicate chunks (see Replication) so a node loss never loses data — realizing the durable principle.
D4 — The metadata service & delta-sync
- Metadata DB holds each file's ordered chunk-hash list, version number, and per-device sync cursor — small rows, sharded by user or file (see Sharding).
- Delta-sync: when a file changes, only its chunk list and the new chunks change; the service tells other devices 'file X moved to version N, here are the chunk hashes you're missing'.
- Notify quickly: push or long-poll the change to other devices, decoupled through a queue so uploads and notifications don't block each other.
- Cache hot metadata (see Caching) so the common 'what version am I on?' check is instant.
-- The file is metadata; the bytes live in the chunk store, keyed by hash.
CREATE TABLE file_version (
file_id BIGINT NOT NULL,
version INT NOT NULL,
name TEXT,
size_bytes BIGINT,
updated_at TIMESTAMP,
PRIMARY KEY (file_id, version) -- every version is kept -> history
);
-- Ordered chunk list for a version: position matters (reassembly order).
CREATE TABLE file_chunk (
file_id BIGINT NOT NULL,
version INT NOT NULL,
position INT NOT NULL, -- 0,1,2,... = page order
chunk_hash CHAR(64) NOT NULL, -- content address into the chunk store
PRIMARY KEY (file_id, version, position)
);// Device B has version N-1; the server moved file X to version N (D4).
function syncDiff(localHashes, remoteHashes) {
const have = new Set(localHashes);
// Only the chunks whose content actually changed need downloading.
const toDownload = remoteHashes.filter((h) => !have.has(h));
// Reassemble the file in the server's declared order, reusing local chunks.
const plan = remoteHashes.map((h) =>
have.has(h) ? { hash: h, source: "local" } // unchanged -> free
: { hash: h, source: "remote" } // changed -> fetch
);
return { toDownload, plan }; // a one-line edit pulls ~1 chunk, not the file
}D5 — Conflicts & cross-cutting concerns
- Conflicts: two devices edit the same file offline, producing two divergent chunk lists for the same version. Detect it via version vectors, then keep both (the familiar 'conflicted copy') rather than silently losing an edit — a predictable, non-destructive default.
- Consistency: devices converge after sync; they are not identical every instant — eventual consistency is an accepted trade (see Consistency models).
- Idempotency: re-uploading a chunk that already exists, or replaying a sync, must be a no-op (see Idempotency).
- Quotas & rate limits: cap per-user storage and throttle sync traffic (see Rate limiting).
- Observability: watch sync lag, dedup ratio, chunk-upload p99, and conflict rate (see Observability).
Why 'keep both', and why not last-write-wins?
When two devices edit the same file offline, something has to give. The simplest rule is last-write-wins: whoever syncs later overwrites the other. It's trivial to build and silently destroys someone's work — the one outcome users never forgive in a sync tool. The safe default is to detect the divergence (two edits branching from the same version) and keep both as a 'conflicted copy', letting a human decide. It's a touch more code and a slightly messier folder, but it never loses an edit.
| Approach | What it buys | The gap it can't fill |
|---|---|---|
| Last-write-wins | Trivial; the folder always has one version. | Silently deletes the loser's edits — data loss, the worst failure for a sync product. |
| Keep both (conflicted copy, chosen) | Never loses work; the user resolves intentionally. | A temporary duplicate file to clean up — a small, visible, honest cost. |
| Operational merge (auto-merge edits) | Seamless for structured/text files. | Impossible to do safely for arbitrary binary files — only works for specific formats. |
Scaling & bottlenecks — what breaks first
Turn the dial up and file sync fails in a predictable order. Because bytes are deduped and only deltas move, raw bandwidth is rarely the first wall — the pressure shows up in metadata churn and notification fan-out.
| Breaks first as you scale | The symptom | The fix |
|---|---|---|
| Metadata write hotspots | A user hammering saves (or a huge folder) floods the metadata DB with version writes. | Shard metadata by user/file; batch rapid edits; coalesce versions before persisting. |
| Notification fan-out | A shared team folder changes and thousands of devices must all be told at once. | Decouple via a queue; push compact 'version N' deltas, not file contents; coalesce bursts. |
| Chunk store garbage collection | Deleted versions leave orphan chunks that pile up and cost money. | Reference-count chunks; GC off-peak; only delete a chunk when no version points to it. |
| Dedup hash lookups | 'Do you have these hashes?' checks dominate as the chunk catalog grows huge. | Front the hash index with a bloom filter and cache; shard the index by hash prefix. |
Phases E & F — Migration Planning
- Sequence by risk: ship single-device upload with chunking, hashing, and the chunk store first — that proves dedup and the metadata model.
- Add multi-device delta-sync next, with the notification path.
- Add conflict handling and sharing last, since they are the subtle parts best built on a solid sync core — the same expand-contract spirit as the TOGAF commerce scenario.
Phases G & H — Governance & Change
- Governance (G): define SLOs (sync-propagation p99, durability targets), set per-user storage quotas and a version-retention policy, and review that dedup and replication keep costs in budget.
- Change (H): adding file sharing, team folders, or end-to-end encryption is a bounded change — new access rules and key handling over the same chunk/metadata model, not a re-architecture, because files were modeled as chunks from the start.
File sync is the canonical lesson in content-addressed storage — model a file as hashed chunks and dedup, delta-sync, and versioning all become the same idea.
Why it matters
- It teaches content addressing: identify data by the hash of its bytes, and dedup is automatic.
- It turns bandwidth from a whole-file cost into a changed-chunks cost, which is the core efficiency win.
- It makes conflict handling concrete — version vectors and a non-destructive 'keep both' default.
If ignored
- Treat a file as one opaque blob and every small edit re-uploads the whole thing.
- No hashing/dedup and identical content is stored and synced over and over, wasting storage and bandwidth.
- No conflict strategy and concurrent offline edits silently overwrite each other and lose work.
Where it fits
- Phase D holds chunking, hashing, dedup, the chunk store, the metadata service, delta-sync, and conflicts.
- Phase C's 'file = list of hashed chunks' model drives all of it; Phase A's bandwidth-thrifty and durable principles justify it.
- It sits beside Pastebin as another 'big bytes in blob storage, small metadata in a DB' design.
Related topics
- Replication: keeps chunks durable across node loss
- Message queues: decouples upload from device notifications
- Consistency models: devices converge; eventual consistency is the accepted trade
- Design Pastebin: same split: big bytes in blob storage, small metadata in a DB
Interview lens
Questions it unlocks
- Design Dropbox / Google Drive / a file sync service.
- How do you sync a large file efficiently after a tiny edit?
- How do you handle two devices editing the same file offline?
60-second answer
I'd walk it as an ADM track so the chunk model comes first. Phase A sets principles — bandwidth-thrifty, durable, eventually consistent. Phase B names upload, sync, resolve conflicts, and share, with efficient sync and conflicts as the make-or-break parts. Phase C does the key reframing: a file is an ordered list of content-addressed chunks, with a file→chunk metadata map, a chunk store, and per-device sync state. Phase D makes it concrete: the client splits files into chunks and hashes each, uploads only the chunks the server is missing, and the server stores each unique chunk once in blob storage so dedup is automatic; the metadata DB holds the ordered chunk-hash list and versions, sharded per user, and delta-sync tells other devices which chunks they're missing via a queue-backed notification path. Conflicts use version vectors with a non-destructive conflicted-copy default; cross-cutting: idempotency, quotas, rate limits, and observability. E–H ship single-device upload, then multi-device sync, then conflicts, governed by quotas and retention. The headline is that 'a file is hashed chunks' makes dedup and delta-sync fall out of one model.
Common traps
- Treating a file as one blob and re-uploading the whole thing on every small edit.
- Skipping content-addressed hashing, so identical chunks are stored and synced repeatedly.
- Having no conflict strategy, so concurrent offline edits silently clobber each other.