skip to content
jaeaeichsysdes

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

RESUMABLE UPLOAD & DAG TRANSCODINGGLOBAL ABR PLAYBACK (100:1 READS)ENGAGEMENT PIPELINEinitdirect 50GB chunked PUT (bypasses API)metaCDCHLSGETreadmissorigin pullstatic 4s ABR segmentslike/viewbatchhot countsCreator50 GB filechunked PUTViewerABR player1B DAUupload svcpresigned URLsRedis session TTLVideo PGstatus + metaWAL CDCTemporal DAGGOP split360p-4K parallelS3 Raw/HLSmultipart.m3u8 chunksview svcmeta + manifest<1s startupRedis Cachemeta + hot likes<10ms lookupGlobal CDN Edgestatic 4s HLS/DASHSigned CookiesKafkaview / like eventsFlink Windowstumbling aggdual sinkClickHouse OLAPpartition: video_idcreator analytics

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 row
Playback: 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 PUT straight 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 svc invokes S3 CompleteMultipartUpload (zero app-server RAM buffering) and commits status = PROCESSING in Video PG.

2. Parallel GOP transcoding (PG CDC -> Kafka -> Temporal)

  • Zero dual writes: Video PG WAL 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 svc reads metadata + master manifest (.m3u8/.mpd) from Redis (read-through Video PG), and the player pulls static 4-second segments from CDN -> S3 (using CDN Signed Cookies for paid/private streams so cache keys stay shared).
  • 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) so view svc never 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?

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?

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?

esc
⌘B sidebar[ ] prev/next1–5 flowsc copyt theme