Media and real time · Design 19

Design YouTube

Design YouTube in a 45-minute interview: resumable chunked uploads, a parallel transcoding DAG, adaptive bitrate streaming with HLS and DASH, CDN cost and view counting.

AdvancedInterview priority: High55 min
On this page
  1. How to use this page
  2. 1. Clarify the requirements
  3. 2. Back-of-the-envelope estimates
  4. 3. API
  5. 4. Data model
  6. 5. High-level design
  7. 6. Deep dives
  8. 7. Bottlenecks, failures and monitoring
  9. 8. Follow-up questions
  10. Quiz

How to use this page

This page follows the order of a real system design interview. At each step there is a Your turn box: write your own answer first, then open ours and compare. YouTube is two systems joined by storage: a write path that turns a creator's huge file into dozens of streamable versions, and a read path that pushes more bytes per second than almost anything else on the internet. Most candidates under-design the second.

PhaseTime in a 45-min interviewWhat you produce
1. Clarify requirements5 minUpload, watch, video page; what's out of scope
2. Estimate5 minStorage/day, outgoing bandwidth, transcoding work
3. API5 minResumable upload, create video, manifest URL
4. Data model5 minMetadata, renditions, originals, segments, counters
5. High-level design10 minUpload → transcode → segment store → CDN → player
6. Deep dives10–15 minUploads, transcoding DAG, adaptive bitrate, CDN, view counts
7. Wrap up2–3 minBottlenecks, failures, monitoring

Creators upload videos; viewers watch them with smooth playback on any device and network. Show a video page with title, views and likes, and basic search by title. Skip live streaming, comments, recommendations and monetisation.

1. Clarify the requirements

Your turn: scope it

The interviewer says: "Design YouTube." Write the questions you'd ask, then 4–5 functional and 4–6 non-functional requirements with targets, and what you'd leave out.

Compare with our answer

Useful questions: How large are uploads? How quickly must a video be watchable after upload? Which devices and networks? Live streaming? Do view counts need to be exact and instant? Recommendations?

A strong answer mentions: upload, watch, video page with counts, processing status · time to first frame (< 2 s) and rebuffering as the playback targets · durability of originals · processing in minutes · live, comments, recommendations and ads out of scope.

Functional: what it must do

  • Upload a video: Files up to many GB, from flaky connections
  • Watch a video: Smooth playback on any device
  • Video page: Title, description, view and like counts
  • Search by title
  • Processing status: “Processing… 60%” for the creator

Out of scope

Live streamingCommentsRecommendationsAds and monetisation

Non-functional: how well it must work

QualityTargetWhy
Playback start< 2 sViewers leave if it spins
SmoothnessMinimal rebufferingAdapt quality instead of stalling
Availability99.99% for playbackUploads can tolerate a little more
DurabilityOriginals never lost
Scale~1 B hours watched per dayBandwidth is the dominant cost
Upload processingMinutes, not hoursCreators want to publish

Two playback terms. Time to first frame is how long from pressing play to seeing video. Rebuffering is the spinner in the middle of a video, when the player has run out of downloaded video. Viewers forgive a slightly blurry picture far more readily than a spinner, which is why the design trades quality for continuity.

2. Back-of-the-envelope estimates

Your turn: the numbers

Assume 500 hours of video uploaded every minute, about 2 GB per raw hour, stored output 1.5× the raw size, 1 billion hours watched a day at an average of 3 Mbit/s. Work out new storage per day, average outgoing bandwidth, and video starts per second if a session averages 12 minutes.

Compare with our answer
  • Uploads: 500 h × 1,440 min = 720 K hours/day.
  • Storage: 720 K × 2 GB × 1.5 ≈ 2 PB/day before replication, so ~0.8 EB a year. Object storage, tiered by age.
  • Bandwidth: 1 B h × 3,600 s × 3 Mbit/s ÷ 86,400 s ≈ 125 Tbit/s ≈ 15 TB/s on average, more in the evening peak.
  • Starts: 1 B h ÷ 0.2 h per session ÷ 86,400 ≈ 58 K video starts/s, each fetching a page and a manifest.
  • Transcoding: 500 hours of input every minute is 30,000 hours of video per hour. If one machine could encode the whole quality ladder at real-time speed (a rough assumption), that's ~30,000 machines busy all the time.

A strong answer mentions: storage in PB/day · bandwidth in TB/s as the headline · transcoding as a large, parallel batch workload · metadata as small · peak vs average.

Assumptions: hours uploaded per minute 500; raw upload size per hour 2 GB; stored size after transcoding (x raw) 1.5; hours watched per day 1 B; average stream (mbit/s) 3.

NumberEstimateWhy it matters
Hours uploaded per day720 K500 × 1,440 = 720 K hours a day.
New storage per day2.2 PB≈ 2 PB a day, before replication.
Transcoding work (video-hours / s)8.33Each hour is encoded into ~6 qualities × 2 codecs.
Average outgoing bandwidth15.6 TB/s≈ 15 TB per second: only possible with CDNs in ISPs worldwide.
Video starts per second57.9 K / sAssuming ~12-minute average sessions.
  • Bandwidth, not storage, is the headline cost: serve from CDN edges inside ISPs.
  • Most views go to a small share of videos: cache the popular ones everywhere, the long tail in fewer places.

Compare the two big numbers: 2 PB a day comes in, but about 1.3 EB a day (15 TB/s × 86,400 s) goes out: roughly 600 times more. Storage is a large cost; bandwidth is the defining one. At even a fraction of a cent per gigabyte, serving that from ordinary cloud egress would cost millions of dollars a day, which is why YouTube places cache servers inside internet providers' networks.

3. API

Your turn: the API

How does a creator's browser upload a 10 GB file over hotel Wi-Fi? And what does the player ask for: one video file, or something else?

Compare with our answer

A strong answer mentions: a call that starts an upload session · chunks sent with their byte offset · a way to ask "how much did you get?" after a drop · a separate call to create the video with title and visibility · the player fetching a manifest from the CDN, then segments · status polling for "processing".

CallRequestResponseNotes
POST /v1/uploads{ fileName, size, contentType }{ uploadId, uploadUrl }Starts a resumable upload session
PUT {uploadUrl}?part=Nvideo chunk (e.g. 8 MB)200Chunks can retry individually; resume after network drops
POST /v1/videos{ uploadId, title, description, visibility }201 { videoId, status: "processing" }
GET /v1/videos/{id}–{ title, views, likes, manifestUrl, status }Video page
GET {cdn}/videos/{id}/master.m3u8–HLS master manifestLists every quality; the player picks
GET /v1/search?q=–{ videos[] }Title search

The player never downloads "the video". It downloads a manifest (a small text file listing every available quality and where its pieces are), then a stream of segments (2–6 second pieces of video at one quality). Both come from the CDN, not from the video API, which only serves the page data.

4. Data model

Your turn: the storage

List what you store, where, and why. Which data is tiny and relational, and which is huge and immutable?

Compare with our answer

A strong answer mentions: video metadata in sharded SQL · renditions (which qualities exist) · originals kept in cheaper storage for re-encoding · segments and manifests in object storage behind the CDN · view counts outside the metadata row, fed by a stream.

videos (metadata) Sharded SQL (Vitess / MySQL)

  • video_id, uploader_id
  • title, description, visibility
  • status: uploading | processing | ready
  • duration, created_at

YouTube famously scaled MySQL with Vitess; metadata is relational and modest in size.

renditions SQL

  • video_id, codec, resolution, bitrate
  • manifest_path

Which qualities exist and where their segments live.

raw uploads Object storage (cold after processing)

  • uploads/{uploadId}/original.mov

The original is kept so videos can be re-encoded with better codecs later.

segments Object storage + CDN

  • videos/{id}/1080p/seg_00042.m4s
  • videos/{id}/master.m3u8

Each rendition is cut into 2–6 second segments the player requests one by one.

view counts Counters + stream processing

  • views:{videoId}
  • likes:{videoId}

Billions of view events a day: aggregate in a stream, de-duplicate bots, update counts periodically.

Comments on the data:

  • Metadata is small: even billions of videos at a few KB each is terabytes, not petabytes. YouTube famously scaled MySQL with Vitess, a sharding layer it built and later open-sourced.
  • Keep the original. Codecs improve every few years; with the original you can re-encode popular videos into a new codec (AV1, for example) and save bandwidth on every future view. Originals are read rarely, so they go to a cold, cheap storage class.
  • Segments are immutable: videos/{id}/1080p/seg_00042.m4s is never rewritten, so CDN caches never need invalidating.
  • Counts are not columns you update per view. They're derived from a stream of view events (see the last deep dive).

5. High-level design

Your turn: draw it

Sketch the upload path and the watch path. Which components are on both paths, and which part of the system carries most of the bytes?

Compare with our answer

Only the storage layer is shared. The upload path is a batch pipeline (upload service, raw store, queue, transcoders). The watch path is page data from the video API plus segments from the CDN, which carries nearly all the bytes. People often route video through the API servers, or forget the manifest.

The two paths, then upload, transcoding and playback traced through them

  1. Two separate paths. The write path: an upload service with resumable uploads, raw storage, a job queue and a fleet of transcoders writing segments. The read path: a video API for metadata and search, and a CDN that serves segments from servers close to viewers.
  2. Uploading: the creator’s browser opens a resumable session and sends the file in chunks, so a dropped connection only re-sends one chunk. When the last chunk lands, the original is in raw storage and a processing job is queued.
  3. Transcoding: the video is split into short pieces processed in parallel. Each piece is encoded into a ladder of qualities, from 144p to 4K, in more than one codec, then cut into segments with a manifest listing them all.
  4. Watching: the player fetches the page data, then the manifest from the nearest CDN edge, then segment after segment. Every few seconds it checks its download speed and picks the next segment’s quality to match.
ComponentWhat it does
Upload serviceResumable chunked uploads; creates metadata
Raw storeOriginals, kept for future re-encoding
Job queue + transcodersParallel encoding into a ladder of qualities and codecs
Segment storeSegments and manifests, the origin for the CDN
CDN edgeCaches popular segments near viewers, often inside ISPs
Video APIMetadata, page data, search
View counterStream aggregation of view events

Trace the watch path out loud, because it's what users feel:

  1. The player loads the page data from the video API (title, counts, manifest URL): one small request.
  2. It fetches the master manifest from the nearest CDN edge, listing every quality.
  3. It picks a starting quality (usually a low one, to start fast), downloads the first segments, and starts playing as soon as a couple of seconds are buffered.
  4. For every following segment, it re-decides the quality from measured throughput and buffer level.
  5. It sends view and progress events to the counter service in the background.

6. Deep dives

Your turn: the hard parts

Write two or three sentences on each before reading: How does a 10 GB upload survive a dropped connection? How is a 2-hour video ready in minutes, not hours? How does playback adapt to a train going through a tunnel? Where do 15 TB/s come from? How do you count views on a viral video?

Compare with our answer

A strong answer mentions:

  • An upload session, chunks with offsets, and resuming from the last byte the server confirmed.
  • A DAG: split at keyframes, encode chunks × renditions in parallel, package, publish low qualities first.
  • Adaptive bitrate over HLS or DASH: a ladder of qualities in short segments, chosen per segment.
  • Tiered CDN with caches inside ISPs, popular videos pre-positioned, efficient codecs.
  • View events through a stream, de-duplicated and filtered for bots, counts updated periodically.

Resumable, chunked uploads

The problem. A creator uploads 10 GB over hotel Wi-Fi. A single HTTP request that dies at 9.8 GB restarts from zero.

OptionHowCatch
One big requestPUT the whole fileAny drop restarts everything
Chunked, not resumableSend numbered chunks; restart the session on failureBetter, but a browser crash loses the session
Resumable session (chosen)Server creates a session id; client sends chunks with byte offsets; after any failure it asks "how much do you have?" and continuesSessions must expire; chunks need checksums

How it works (Google's resumable upload protocol and the open tus protocol both look like this): POST /uploads returns a session URL. The client sends PUT requests carrying Content-Range: bytes 0-8388607/10737418240 and so on. After a drop, it sends an empty request asking for status; the server answers with the last byte it has safely stored, and the client continues from there. Only the unconfirmed chunk is resent. Large chunks (8–64 MB) keep the per-request overhead low on fast links; smaller ones lose less on flaky links.

The transcoding pipeline as a DAG

Transcoding means decoding the uploaded video and re-encoding it into other resolutions, bitrates and codecs. A codec is the compression format: H.264 plays everywhere; VP9 and AV1 need roughly 30–50% fewer bits for similar quality per generation, but cost much more CPU to encode. The set of qualities produced (144p, 240p, 360p, 480p, 720p, 1080p, 4K) is the encoding ladder.

Encoding a 2-hour film into a dozen versions on one machine, one after another, takes many hours. So the work is split into a DAG (directed acyclic graph) of small jobs:

The transcoding DAG: split, encode in parallel, package

  1. Probe and validate: is it a real video? Duration, resolution, frame rate.
  2. Split into chunks of about a minute, at keyframes. A keyframe is a frame stored whole; the frames between keyframes are stored as differences, so a cut anywhere else would leave a chunk that can't be decoded on its own.
  3. Encode every chunk into every rendition, in parallel across many workers.
  4. Package: join the chunks per rendition, cut them into 2–6 s segments, write the manifests.
  5. Publish: generate thumbnails, mark renditions ready, update the status.

Publish in stages: make 360p and 720p H.264 available first so the video is watchable in minutes, and add 4K and the expensive codecs afterwards. Many services only spend AV1 encoding on videos that turn out to be popular, because the bandwidth savings only pay back the encoding cost when many people watch.

Adaptive bitrate streaming: HLS and DASH

The problem. A viewer on a train moves from 4G to almost nothing and back. One fixed-quality file either looks bad all the time or stalls in every tunnel.

Adaptive bitrate (ABR) streaming encodes the video at several qualities, cuts each into short segments that line up in time, and lets the player choose the quality of each next segment. The two standard formats:

HLSDASH
FromAppleMPEG (an international standard)
Manifest.m3u8 text playlists.mpd XML file
Where it's neededRequired on Apple devices and SafariWidely used elsewhere, including most of YouTube's playback
SegmentsMPEG-TS or fragmented MP4Fragmented MP4

Both can share the same fragmented MP4 segments (a format called CMAF), so you store the video once and write two manifests.

Adaptive bitrate: each segment's quality follows the network

The player's choice uses two signals. Throughput: how fast did the last few segments download? Buffer level: how many seconds of video are already downloaded? A full buffer allows a risky step up; a nearly empty one demands a step down now. Start low so the first frame appears fast, then climb.

The CDN and the cost of 15 TB/s

No data centre can send 15 TB/s, and viewers far away would wait for each segment. A CDN (content delivery network) caches segments on servers near viewers; see CDNs. YouTube's version goes a step further, with three tiers:

TierWhereHolds
Edge caches inside ISPsIn the internet provider's own network (Google Global Cache)The popular videos for that area
Regional cachesGoogle's points of presenceA wider set, including the long tail of less-watched videos
OriginSegment storage in data centresEverything

Video popularity is extremely skewed: a small share of videos gets most views. Popular segments are pushed to edges in advance, often overnight when links are quiet, and serve most bytes from a few network hops away. The long tail is fetched from regional caches on demand. Every percentage point of edge hit ratio is a large saving in long-distance traffic, and every codec generation cuts the bytes themselves.

Counting views

A viral video can get hundreds of thousands of views a second. UPDATE videos SET views = views + 1 would turn one row into the hottest spot in the database. And a "view" must be a real one: bots and refresh loops inflate counts, and creators are paid on them.

The pipeline: players send view events to a log such as Kafka; a stream processor de-duplicates (same viewer and video within a time window counts once), filters suspicious traffic, and aggregates per video per few seconds; the aggregates are added to sharded counters, and the video page reads the total from a cache. Deeper fraud checks run later in batch and can correct counts downwards. That's why counts lag and occasionally drop; for years YouTube famously paused new videos' counts at around 300 while it verified the views.

7. Bottlenecks, failures and monitoring

Scaling bottlenecks

BottleneckFix
Outgoing bandwidthMulti-tier CDN, ISP caches, efficient codecs (VP9, AV1)
Transcoding burstsQueue + autoscaled workers; prioritise popular creators; GPU/ASIC encoders
Storage growthTiered storage: hot segments vs cold originals; drop unused renditions of old, unwatched videos
Metadata loadSharded MySQL (Vitess) + heavy caching of video pages

When things fail

FailureWhat happens
Transcoder crashesThe chunk job is retried; output is idempotent
CDN edge downClients fail over to another edge / regional cache
Upload interruptedResume from the last confirmed chunk
Origin region outageSegments replicated across regions; CDN pulls from the next origin

What to monitor

Time to first frameRebuffering ratioCDN hit ratioTranscoding queue lagUpload success rateEgress per region

8. Follow-up questions

Your turn: the interviewer pushes

Answer in order before opening ours. 1) Add live streaming with under 10 seconds of delay. 2) A creator uploads a 12-hour 8K video. What changes? 3) Finance asks you to cut bandwidth costs by 20% without hurting quality. What do you try?

Compare with our answer

A strong answer mentions:

  1. Ingest over RTMP or SRT, transcode in real time into 1–2 s segments, a manifest that keeps growing, and the CDN serving a "live edge"; low-latency HLS or DASH with partial segments for a few seconds of delay.
  2. Larger chunks and longer upload sessions; more chunks in the DAG; publish lower qualities first; storage-class choices for a huge original; limits per account.
  3. Re-encode the most-watched videos with AV1 or VP9; per-title encoding (pick bitrates per video, since a cartoon needs fewer bits than sport); raise edge hit ratio by pre-positioning; cap default quality on small mobile screens.
How would you add live streaming?

Ingest RTMP/SRT, transcode in real time into short segments (1–2 s), and publish a manifest that grows; viewers lag a few seconds behind.

How do you protect paid content?

DRM (Widevine, FairPlay): segments are encrypted, the player gets keys from a licence server after an entitlement check.

How do thumbnails work?

Generated during transcoding (several candidate frames), stored as images and served by the CDN.

More senior follow-ups
  • DRM for paid content. Segments are encrypted; the player gets a decryption key from a licence server (Widevine, FairPlay, PlayReady) after an entitlement check. The CDN still caches the encrypted segments.
  • Per-title and per-scene encoding. Instead of a fixed ladder, analyse each video's complexity and choose the bitrates that reach a target quality; Netflix popularised this and reported large savings.
  • Search. Titles and descriptions stream into an inverted index (Elasticsearch-style), ranked with popularity signals; it's a separate system fed by metadata change events.
YouTube on one page
  • Numbers: 720 K hours uploaded/day ≈ 2 PB/day stored; 1 B hours watched/day at 3 Mbit/s ≈ 15 TB/s out (~600× the ingest); ~58 K starts/s.
  • Upload: resumable session, chunks with byte offsets, ask-and-resume, checksums; expire abandoned sessions.
  • Transcode: DAG = probe → split at keyframes → encode chunk × rendition in parallel → package → publish; low qualities first; retry limits and a dead-letter queue.
  • Ladder: 144p … 4K × H.264 / VP9 / AV1; expensive codecs for popular videos; keep originals for re-encoding.
  • ABR: HLS (.m3u8) or DASH (.mpd), 2–6 s segments, quality chosen per segment from throughput and buffer.
  • CDN: ISP edges → regional → origin; pre-position popular videos; request coalescing for viral ones; immutable segments.
  • Views: events → Kafka → de-dupe + bot filter + aggregate → sharded counters; counts lag by design.
  • Watch: time to first frame, rebuffering ratio, CDN hit ratio, transcode lag.
Mock interviewPractise it as a mock interview: uploads, transcoding and playbackOpens in the ByteAtlas lab. Your progress is saved in this browser.
Check what stuck

1. A creator's 10 GB upload over hotel Wi-Fi keeps failing near the end. What is the best design change?

2. Why must the transcoding pipeline split a video at keyframes rather than at exact one-minute marks?

3. A viewer's bandwidth drops from 8 to 1.5 Mbit/s while watching in 1080p. What does an adaptive bitrate player do?

4. 1 billion hours watched a day at 3 Mbit/s. What is the average outgoing bandwidth, roughly?

5. Why keep each original upload after transcoding has finished?

6. Finance wants lower bandwidth costs. Which change saves the most for the least effort?

7. A video goes viral, and its view count updates in jumps every few seconds and once even goes down. Why?

Score 60% or more and the lesson is marked complete.

Passing the quiz also marks it complete. Progress is saved in this browser only.