Design a Video Streaming Platform (YouTube / Netflix)
1B DAU video streaming with 100:1 read/write ratio: 50 GB resumable S3 multipart uploads, Temporal parallel GOP transcoding, CDN adaptive bitrate playback, and Flink/ClickHouse engagement pipelines.
The whiteboard
Trace 50GB upload, DAG transcode, ABR playback, and views & likes below — tying together Idempotency & Outbox, Queues vs Event Logs, and Caching & Failure Modes.
whiteboard · press 1–5 to trace flows
100:1 read-heavy pipeline: direct S3 multipart uploads, GOP-split Temporal DAG transcoding, static CDN ABR playback, and Flink dual-sink counters.Keeps 50 GB binaries off API servers, isolates transcode retries to single chunks, and serves 1B DAU from edge caches.
Scale & APIs
50 GB
resumable multipart upload
100:1
read-to-write ratio · CDN egress
< 1 s
global ABR playback startup
Scale: 1B DAU · 5M uploads/day (~100 RPS) · 30K+ RPS metadata reads · PB/day CDN egress
Upload: POST /upload/session -> { session_id } (Redis SET NX EX 3600) GET /upload/chunk/:id -> { presigned_s3_url } POST /upload/chunk/:id/complete { etag } -> 200 OK POST /upload/complete -> S3 CompleteMultipartUpload + Video PG rowPlayback: GET /video/:id -> { meta, manifest_url (.m3u8/.mpd), likes } POST /video/:id/like -> 202 Accepted (Kafka event)How it works
1. Resumable 50 GB uploads (Creator -> direct S3)
- Bypass API servers: Clients split 50 GB files into chunks and
PUTstraight to S3 via presigned URLs while Redis tracks active sessions (EX 3600) and S3 lifecycle rules clean up abandoned parts. - Server-side stitching: On
/upload/complete,upload svcinvokes S3CompleteMultipartUpload(zero app-server RAM buffering) and commitsstatus = PROCESSINGinVideo PG.
2. Parallel GOP transcoding (PG CDC -> Kafka -> Temporal)
- Zero dual writes:
Video PGWAL CDC follows the outbox pattern into Kafka -> Temporal so every completed upload triggers transcoding reliably. - Chunk-level retries: Temporal splits the raw video on GOP (Group of Pictures) boundaries and encodes
360p / 720p / 1080p / 4K+ thumbnails in parallel — a preempted spot worker loses one 10-second chunk, never a 4-hour job.
3. Global <1s ABR playback (CDN -> S3)
- Static segment URLs:
view svcreads metadata + master manifest (.m3u8/.mpd) from Redis (read-through Video PG), and the player pulls static 4-second segments fromCDN -> S3(using CDN Signed Cookies for paid/private streams so cache keys stay shared).
4. Dual-sink engagement (Kafka -> Flink -> ClickHouse + Redis)
- Separate OLAP from hot reads: Flink tumbling windows batch counts into ClickHouse (
partition: video_id) for creator analytics and materialize hot counters into Redis (<10ms) soview svcnever hits ClickHouse; deduplicate per-user likes in a lightweight(user_id, video_id)store.
lesson
Two traps interviewers always probe on YouTube: (1) never stitch a 50 GB upload in app memory — use S3 CompleteMultipartUpload, and (2) never query ClickHouse on the 30K+ RPS video-page read path — materialize hot counts into Redis.
Check yourself
interactive · stress-test this streaming design against classic YouTube/Netflix probes
01 · Why not per-chunk presigned S3 URLs for playback?
4s segments · 1B DAU · CDN cache hit rate
A teammate proposes returning a freshly signed S3 presigned URL for every 4-second video segment so only logged-in users can watch. What goes wrong at 1B DAU?
Select an option to check the trade-off.
02 · Worker crashes 90% through transcoding a 4-hour 4K video
4-hour 4K video · spot worker crash · fault tolerance
A spot transcoding worker is preempted 90% through encoding a 4-hour 4K video. How does your Temporal DAG avoid wasting 90% of the compute?
Select an option to check the trade-off.
03 · Why Flink writes likes to BOTH ClickHouse and Redis
30K+ RPS video reads · OLAP vs OLTP · <10ms lookup
ClickHouse already stores all aggregated views and likes per video. Why does Flink also materialize hot counts into Redis?
Select an option to check the trade-off.
WALstorage
Write-Ahead Log: an append-only disk log written before mutating in-memory structures so crashes never lose committed writes.
outbox patternmessaging
Writing a domain change and its outgoing event to the same DB transaction, then relaying the event asynchronously to avoid dual writes.