Design a video streaming platform like YouTube or Netflix.
Upload once, transcode into many sizes, cut into segments, let the CDN do the streaming.
Transcode into an adaptive bitrate ladder of small segments, so the player picks quality per segment and the CDN caches them.
- Upload straight to object storage
- A queue of transcoding jobs, one per rendition
- The CDN serves almost all bytes, so egress is the cost to optimise
1. Requirements
- Upload videos (creators), transcode to multiple resolutions, stream on any device with adaptive quality, search and recommendations, view counts.
- Smooth playback (fast start, minimal rebuffering) worldwide; uploads can take minutes to process.
2. Estimates
500 hours of video uploaded per minute; 1 B hours watched per day. Storage grows by petabytes per year (each video is stored in many renditions). Egress bandwidth is the dominant cost, hence CDNs.
3. Build it step by step
We grow the platform one stage at a time. In each diagram the parts marked NEW were added in that stage.
Stage 1: upload and play the original file
Flow: 1โ2. The creator uploads a video; the service stores the file and a metadata row. 3. Viewers download the original file.
Problem: a 4K original is huge, many devices cannot play its codec, slow networks stall, and all bytes flow through our servers.
Stage 2: direct uploads and an asynchronous transcoding pipeline
Flow:
- The Upload Service issues presigned URLs; the client uploads chunks directly to S3 (resumable).
- An event triggers the pipeline.
- The video is split into segments and transcoded in parallel into a ladder of resolutions and bitrates; thumbnails and captions are generated. The video becomes "ready" when all renditions exist.
Problem: viewers still download fixed files from a central origin: slow start, rebuffering and enormous egress cost.
Stage 3: adaptive streaming through a CDN
Flow:
- Segments (2โ10 s) and manifests are cached at CDN edges near viewers.
- The player fetches the manifest, then segment by segment, choosing the rendition that fits its measured bandwidth and buffer (adaptive bitrate).
Problem: discovery, metadata, recommendations and view counts are still missing.
Final architecture
End-to-end: 1โ3. Uploads go straight to S3, the pipeline transcodes in parallel and publishes segments. 4. Viewers stream adaptively from the CDN. 5. Players send playback events to Kafka, which feed view counts (stream aggregation) and recommendations; the Metadata Service serves titles, search and access checks with signed segment URLs.
4. Deep dives
- Upload: resumable, chunked uploads straight to object storage with presigned multipart URLs; the Upload Service only creates the video record and issues URLs.
- Transcoding pipeline: split the video into segments (for example 4โ10 s GOP-aligned chunks) and transcode them in parallel into a ladder of resolutions and bitrates (240p to 4K) and codecs (H.264, VP9/AV1), as a DAG of tasks orchestrated through a queue or workflow engine; retries per chunk; content-aware encoding picks bitrates per title.
- Adaptive bitrate streaming: package as HLS or MPEG-DASH: small segments plus a manifest listing renditions. The player measures bandwidth and buffer level and switches renditions per segment.
- CDN: segments are immutable and highly cacheable; Netflix places its own appliances (Open Connect) inside ISPs and pre-positions popular titles overnight. Long-tail videos are served from regional caches or origin.
- Metadata: titles, owners, renditions and status in a relational or document store, cached; search through Elasticsearch.
- View counting: playback events go to Kafka and are aggregated in streams (approximate in real time, exact in batch), never as a database update per view.
- DRM and access: signed URLs or tokens for segments, Widevine/FairPlay/PlayReady for premium content.
Follow-up questions interviewers ask
Try answering each one before you open it.
How does the player decide which quality to stream?
It downloads the manifest, starts with a conservative rendition for a fast start, then for each next segment estimates throughput (bytes per second of recent downloads) and checks its buffer level. With a healthy buffer and high throughput it steps up; when the buffer drains it steps down to avoid a stall. Modern algorithms (BOLA, MPC) balance quality, rebuffering risk and quality switches.
How would you reduce transcoding cost?
Transcode popular content into the full ladder and long-tail content into fewer renditions (or lazily on first request), use more efficient codecs for the most-watched titles (AV1 saves bandwidth, which dominates cost), use Spot or preemptible instances for the stateless, retryable chunk jobs, and use hardware encoders (GPUs or dedicated ASICs) where quality allows.