Design a Video Streaming Platform (YouTube / Netflix)
Upload, process and stream video to hundreds of millions of viewers — resumable uploads, the transcoding pipeline as a DAG of parallel chunk jobs, codecs and bitrate ladders, HLS/DASH adaptive bitrate streaming, CDN strategy (including Netflix Open Connect), metadata and view counts, live streaming differences, and cost control.
1. Requirements
Functional
- Upload videos (up to several GB); process into streamable formats.
- Watch videos on any device/network with adaptive quality; seek; resume.
- Metadata: title, description, thumbnails; search and recommendations (out of scope beyond a mention); likes, comments, view counts.
Non-functional
- 500M DAU; 1B hours watched/day.
- Fast startup (< 2 s), minimal rebuffering.
- Highly available playback; uploads can take minutes to process.
- Cost efficient: bandwidth and storage dominate cost.
2. Estimation
| Quantity | Value |
|---|---|
| Uploads | 500 hours/minute ≈ 720k hours/day |
| Storage per hour (all renditions + codecs) | ~3–5 GB → ~3 PB/day new (+replication) |
| Watch bandwidth | 1B h/day ÷ 24 h ≈ 42M concurrent streams × ~2.5 Mbps ≈ ~100 Tbps average egress (~1 EB/day) |
| Metadata reads | ~100k–500k QPS |
Conclusion: egress bandwidth and storage dwarf everything else → CDNs, efficient codecs, and tiered storage decide the design.
3. High-level design
4. Deep dives
Upload
Resumable multipart uploads (chunks retried independently), checksum per chunk, direct to object storage via pre-signed URLs; the metadata row is created first with status = uploading.
Transcoding DAG
| Rendition | Resolution | Bitrate (H.264, approx.) |
|---|---|---|
| 240p | 426×240 | 0.3–0.7 Mbps |
| 480p | 854×480 | 1–2 Mbps |
| 720p | 1280×720 | 2.5–4 Mbps |
| 1080p | 1920×1080 | 4.5–6 Mbps |
| 4K | 3840×2160 | 12–20 Mbps (AV1/HEVC ~40–50% less) |
Netflix uses per-title / per-shot encoding — the ladder is optimised per content (cartoons need far fewer bits than action scenes).
Manifests
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=640x360,CODECS="avc1.4d401e,mp4a.40.2"
360p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2800000,RESOLUTION=1280x720,CODECS="avc1.4d401f,mp4a.40.2"
720p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080,CODECS="avc1.640028,mp4a.40.2"
1080p/index.m3u8
Data model
| Data | Store |
|---|---|
| Video metadata (title, owner, status, renditions) | sharded SQL / Vitess (YouTube uses Vitess on MySQL) |
| Segments, raw uploads, thumbnails | object storage, tiered (hot → infrequent → archive for unpopular originals) |
| Views, likes counters | stream aggregation → counter store + cache |
| Comments | wide-column store partitioned by video ID |
| Watch history / resume position | KV store keyed by user (written every ~10 s from heartbeats) |
Protecting content
Signed URLs or tokens (short TTL) for segments; DRM (Widevine, FairPlay, PlayReady) with license servers for premium content; geo-restrictions at the playback API.
5. Cost control
- Efficient codecs for popular content (AV1 saves bandwidth on the videos that matter most).
- Lazy transcoding / fewer renditions for long-tail content.
- Storage tiering; delete intermediate artifacts.
- ISP-embedded caches reduce transit costs.
- Spot/preemptible instances for transcoding (jobs are retryable chunks).
6. Trade-offs
| Decision | Choice |
|---|---|
| Streaming protocol | HLS/DASH over HTTP (CDN-friendly) vs WebRTC (low latency, hard to scale) |
| CDN | push pre-positioning (Netflix) vs pull caching (YouTube) |
| Transcode timing | eager for all renditions vs lazy for long tail |
| View counts | approximate real-time + exact batch reconciliation |
Interview questions
Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.