Tech Interview RoomStudy guides

System Design

Design a video streaming platform like YouTube or Netflix.

Advanced ยท 3 min read ยท Lesson 15 of 36 in System Design

๐ŸŽฌ
Design at a glance

Upload once, transcode into many sizes, cut into segments, let the CDN do the streaming.

500 hvideo uploaded per minute
1 B hwatched per day
2โ€“10 ssegment length
PBstorage growth per year
Core building blocks
Pre-signed upload to S3โ†’Transcoding workersโ†’HLS/DASH segmentsโ†’CDN edge cachesโ†’Metadata + recommendations
Key decision

Transcode into an adaptive bitrate ladder of small segments, so the player picks quality per segment and the CDN caches them.

Trade-off
Pre-transcode everything: instant playback, lots of storage
vs
Transcode on demand: less storage, slow first view
Remember
  • 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

Stage 1: store and serve the raw upload
Creators
Upload client
โ†“1. upload file
Service
Video Service
โ†“2. save file + metadata
Storage
Object storage (S3)๐Ÿ—„๏ธ Video DB
โ†“3. download the whole file to play
Viewers
Browser player

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

Stage 2: presigned upload + transcoding workers
Creators
Upload client (resumable)
โ†“1. presigned multipart upload
Ingest
Upload ServiceRaw videos (S3)
โ†“2. VideoUploaded event
Processing
+Kafka jobs+Transcoding workers (FFmpeg)+Thumbnail workers
โ†“3. write renditions
Storage
+[storage] Encoded renditions (S3)

Flow:

  1. The Upload Service issues presigned URLs; the client uploads chunks directly to S3 (resumable).
  2. An event triggers the pipeline.
  3. 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

Stage 3: HLS/DASH segments served by a CDN
Storage
Encoded segments + manifests (S3)
โ†“1. origin pull on cache miss
Delivery
+[edge] CDN edge caches
โ†“2. manifest, then small segments
Viewers
Mobile appSmart TVBrowser player

Flow:

  1. Segments (2โ€“10 s) and manifests are cached at CDN edges near viewers.
  2. 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

Final architecture
Creators
Upload client (resumable)
โ†“1. presigned multipart upload
Ingest
Upload ServiceRaw videos (S3)
โ†“2. VideoUploaded event
Processing
Kafka jobsTranscoding workers (FFmpeg on GPU or CPU)Thumbnail + caption workers
โ†“3. HLS and DASH segments
Delivery
Encoded segments (S3)CDN edge caches
โ†“4. stream segments
Viewers
Mobile appSmart TVBrowser player
โ†“5. playback events
Platform
+Metadata Service + [db] Video DB+Recommendation Service+[db] View counts (Cassandra)

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.