Notes
All notes

System design walkthroughs 4: media and storage

Problem. Full interview answers for the bank’s media and storage questions. Part 4 of 6. (1: foundations · 2: feeds · 3: geo & marketplaces · 5: money · 6: AI era)

20. YouTube / Netflix streaming [Netflix, YouTube, Amazon, Meta]

Requirements. Functional: upload, watch at any quality, resume across devices. Non-functional: start under 2s on 4G, never rebuffer mid-stream.

Estimation. 20k uploads/day × 1 GB ≈ 20 TB/day ingress; each video stored ~6× over (transcode ladder 240p–4K); watch bytes dwarf uploads 1000:1 — playback, not upload, sizes the CDN bill.

API. POST /videos (resumable upload), GET /videos/{id}/manifest, GET /segments/{id}/{quality}/{n}, PUT /progress.

Core design. Upload → transcode farm → object storage → CDN; playback is adaptive bitrate (client picks each segment by measured bandwidth, so stalls are a client decision informed by server manifests).

flowchart LR
    U[Upload] --> T[Transcode ladder]
    T --> O[(Object storage)]
    O --> C[CDN]
    C --> P[Player: adaptive segments]

Deep dives. ISP-embedded edge caches (Netflix Open Connect lore), live as a separate low-latency path, DRM license flow, and upload vs playback as different systems sharing only storage.

21. Dropbox / Drive file sync [Dropbox, Google, Microsoft, Box]

Requirements. Functional: files identical everywhere, shareable links, offline edits. Non-functional: sync deltas not files, no lost writes.

Estimation. 100M users × 10 GB = 1 EB logical — but chunk dedup (4 MB blocks, content-hashed) cuts real storage dramatically; say the dedup assumption out loud (30–50% typical).

API. POST /files (chunked, resumable), GET /delta?cursor=, POST /share {path, permissions}, conflict copies on collision.

Core design. Metadata service separate from blob storage (the whole answer in one sentence); chunk + hash + dedup; delta sync uploads changed chunks only; sharing checks permissions on every read, not once at link creation.

22. Search autocomplete / typeahead [Google, Microsoft, Amazon, LinkedIn]

Requirements. Functional: suggestions per keystroke. Non-functional: p99 under 100 ms at typing speed, tolerant of typos.

Estimation. 100k queries/s (every keystroke counts); 10M hot prefixes cached; trie memory in single-digit GBs with FST compression — compute it roughly, don’t hand-wave.

API. GET /suggest?q=&locale=&limit=.

Core design. Prefix trie/FST sharded by prefix, popularity-ranked, debounced client, top prefixes pinned in cache. Personalization as a rerank layer, edit-distance index for typos, trending-query fast lane for freshness.

23. Google Docs real-time collaboration [Google, Microsoft, Notion, Figma]

Requirements. Functional: concurrent edits converge, presence awareness, history. Non-functional: keystroke latency under 100 ms, offline edits that merge later.

Estimation. Sessions are small (tens of collaborators) but numerous; presence heartbeats dominate traffic — separate ephemeral presence from the durable op log in the math.

API. Websocket OP {rev, op}, GET /doc?rev= (snapshot + catch-up), presence channel apart from ops.

Core design. Operation-based sync: Operational Transformation (Docs, central ordering) or CRDTs (peer merge, newer systems); snapshots plus op log for history; comments as a separate model from document ops.