Case study V.10Advanced

Design a Video Streaming Service Like YouTube

Uploads are heavy but rare; views are light but constant and enormous. Most decisions trade compute at upload time for bandwidth at view time, and bandwidth is the bill that matters.

The short answer

Requirements. Upload large files reliably, transcode them for every device and network, stream with a fast start and few pauses, and keep metadata, thumbnails and view counts; playback rarely rebuffers, originals are never lost, and cost matters, because egress dominates the bill.

Uploads
300 TB a day1M videos × 300 MB
Views
100 PB a day1B views × 100 MB
Egress
about 9 Tbps1.2 TB per second, so the CDN is the core

The design. Creators upload in resumable 8 MB chunks to object storage. A transcoding graph splits the original into segments and encodes every segment into several renditions in parallel, then packages them for HLS and DASH and publishes them to the CDN origin. The player reads a manifest, downloads one segment at a time and picks the quality of the next one from its measured throughput and buffer. Popular videos get the expensive codecs, because every byte saved is multiplied by millions of views.

Interview prompt

Design YouTube: creators upload videos, and hundreds of millions of people watch them on any device and any connection.

Requirements and estimates

Functional requirements

  • Upload large files reliably.
  • Transcode into formats for every device and network.
  • Stream with fast start and few pauses.
  • Metadata, thumbnails, view counts.

Non-functional requirements

  • Playback starts quickly and rarely rebuffers.
  • Highly available, and originals are never lost.
  • Cost efficient: egress dominates the bill.

Estimates (assumptions)

Uploads  1M videos per day × 300 MB          = 300 TB per day of originals
Views    1B views per day × 100 MB            = 100 PB per day
Egress   100 PB ÷ 86,400 s                    ≈ 1.2 TB/s, about 9 Tbps
Verdict  bandwidth dwarfs everything, so the CDN is the core of the design

API

API

POST /v1/uploads                    → { uploadId, chunkUrls[] }
PUT  {chunkUrl}                     8 MB chunk, resumable
POST /v1/uploads/{id}/complete
GET  /v1/videos/{id}/master.m3u8    → list of renditions

Whiteboard

What you sketch in the first five minutes: where the bytes go, then how the player picks the next segment.

1. Follow the bytes

Say: uploads are rare and heavy, views are light and enormous; bandwidth is the bill.

upload300 MB, in chunks1234segments240p720p1080p4Kencoded in parallelCDNin: 300 TB a day1M uploadsout: 100 PB a day1B views, about 9 Tbpsbandwidth dwarfs everything:the CDN is the core of the design
  1. An upload of 300 MB arrives in resumable chunks.
  2. It is split into segments and encoded into renditions from 240p to 4K, in parallel.
  3. The renditions go to the CDN, which serves 100 PB of views a day.

Next question: why encode popular videos twice? A newer codec costs more compute once and saves bandwidth on every view.

2. Pick the next segment

Say: the player, not the server, chooses the quality, one segment at a time.

manifest1080p720p480pthe player’s picks, one segment at a timemeasuresthroughputand bufferbuffer drains: go downbuffer grows: go upsegments of a few seconds, HLS or DASHthe video never stops,it gets blurrier for a moment
  1. Each rendition is cut into segments of a few seconds and listed in a manifest.
  2. The player measures throughput and how much video is buffered.
  3. It picks the quality of the next segment: down when the buffer drains, up when it grows.

Next question: what changes for live streaming? No time for a big graph: a few renditions encoded in real time, and segments of one or two seconds.

The transcoding pipeline

Encoding fans out. Every segment and every rendition is an independent task, so a two hour film finishes in minutes on many machines. Thumbnails, captions and content checks run as side branches of the same graph.
RenditionTypical bitrate, H.264Used for
240p≈ 0.4 MbpsWeak mobile networks
480p≈ 1.2 MbpsPhones on cellular
720p≈ 2.5 MbpsLaptops, good mobile
1080p≈ 5 MbpsDesktop, TV
2160p (4K)≈ 15 MbpsLarge TVs on fast broadband

Bitrates vary a lot with content and encoder; treat these as orders of magnitude.

Adaptive bitrate streaming

Each rendition is cut into segments of a few seconds and listed in a manifest (HLS or DASH). The player downloads segments one at a time, measures throughput and how much video is buffered, and picks the quality of the next segment accordingly. That is why video drops to a blurrier picture instead of freezing when the train enters a tunnel.

Spending to save

Newer codecs such as VP9 and AV1 need noticeably less bandwidth for the same quality but cost far more to encode. Spend that compute on popular videos, where every saved byte is multiplied by millions of views; keep the long tail on cheaper encodes. Push popular videos to edge caches ahead of demand; Netflix goes further and places its own cache servers inside internet providers’ networks.

What the interviewer probes next

How do you count billions of views?

Players send events to a stream; a job aggregates them per video per minute and updates counters in batches. Show an approximate count live and reconcile the exact one later, deduplicating by session.

What changes for live streaming?

There is no time for a big transcoding graph. Ingest over RTMP or SRT, transcode a few renditions in real time, and use segments of one or two seconds (low latency HLS). The CDN still does the fan-out.

How do you resume where the viewer stopped?

The player reports its position every few seconds to a per user key value store, read on the next play.

How do you detect copyrighted uploads?

Fingerprint the audio and video during processing and compare against a reference database, then block, monetize or track according to the owner’s policy.

Building blocks used here

Want to run this as a mock interview? See interview prep.

© 2026 Arman Ajabkhani · armantik.com · Privacy