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.
On this page
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.
| Phase | Time in a 45-min interview | What you produce |
|---|---|---|
| 1. Clarify requirements | 5 min | Upload, watch, video page; what's out of scope |
| 2. Estimate | 5 min | Storage/day, outgoing bandwidth, transcoding work |
| 3. API | 5 min | Resumable upload, create video, manifest URL |
| 4. Data model | 5 min | Metadata, renditions, originals, segments, counters |
| 5. High-level design | 10 min | Upload → transcode → segment store → CDN → player |
| 6. Deep dives | 10–15 min | Uploads, transcoding DAG, adaptive bitrate, CDN, view counts |
| 7. Wrap up | 2–3 min | Bottlenecks, 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
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
| Quality | Target | Why |
|---|---|---|
| Playback start | < 2 s | Viewers leave if it spins |
| Smoothness | Minimal rebuffering | Adapt quality instead of stalling |
| Availability | 99.99% for playback | Uploads can tolerate a little more |
| Durability | Originals never lost | |
| Scale | ~1 B hours watched per day | Bandwidth is the dominant cost |
| Upload processing | Minutes, not hours | Creators 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
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.
| Number | Estimate | Why it matters |
|---|---|---|
| Hours uploaded per day | 720 K | 500 × 1,440 = 720 K hours a day. |
| New storage per day | 2.2 PB | ≈ 2 PB a day, before replication. |
| Transcoding work (video-hours / s) | 8.33 | Each hour is encoded into ~6 qualities × 2 codecs. |
| Average outgoing bandwidth | 15.6 TB/s | ≈ 15 TB per second: only possible with CDNs in ISPs worldwide. |
| Video starts per second | 57.9 K / s | Assuming ~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
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".
| Call | Request | Response | Notes |
|---|---|---|---|
POST /v1/uploads | { fileName, size, contentType } | { uploadId, uploadUrl } | Starts a resumable upload session |
PUT {uploadUrl}?part=N | video chunk (e.g. 8 MB) | 200 | Chunks 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 manifest | Lists 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
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_idtitle, description, visibilitystatus: uploading | processing | readyduration, created_at
YouTube famously scaled MySQL with Vitess; metadata is relational and modest in size.
renditions SQL
video_id, codec, resolution, bitratemanifest_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.m4svideos/{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.m4sis 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
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
- 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.
- 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.
- 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.
- 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.
| Component | What it does |
|---|---|
| Upload service | Resumable chunked uploads; creates metadata |
| Raw store | Originals, kept for future re-encoding |
| Job queue + transcoders | Parallel encoding into a ladder of qualities and codecs |
| Segment store | Segments and manifests, the origin for the CDN |
| CDN edge | Caches popular segments near viewers, often inside ISPs |
| Video API | Metadata, page data, search |
| View counter | Stream aggregation of view events |
Trace the watch path out loud, because it's what users feel:
- The player loads the page data from the video API (title, counts, manifest URL): one small request.
- It fetches the master manifest from the nearest CDN edge, listing every quality.
- 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.
- For every following segment, it re-decides the quality from measured throughput and buffer level.
- It sends view and progress events to the counter service in the background.
6. Deep dives
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.
| Option | How | Catch |
|---|---|---|
| One big request | PUT the whole file | Any drop restarts everything |
| Chunked, not resumable | Send numbered chunks; restart the session on failure | Better, 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 continues | Sessions 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
- Probe and validate: is it a real video? Duration, resolution, frame rate.
- 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.
- Encode every chunk into every rendition, in parallel across many workers.
- Package: join the chunks per rendition, cut them into 2–6 s segments, write the manifests.
- 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:
| HLS | DASH | |
|---|---|---|
| From | Apple | MPEG (an international standard) |
| Manifest | .m3u8 text playlists | .mpd XML file |
| Where it's needed | Required on Apple devices and Safari | Widely used elsewhere, including most of YouTube's playback |
| Segments | MPEG-TS or fragmented MP4 | Fragmented 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:
| Tier | Where | Holds |
|---|---|---|
| Edge caches inside ISPs | In the internet provider's own network (Google Global Cache) | The popular videos for that area |
| Regional caches | Google's points of presence | A wider set, including the long tail of less-watched videos |
| Origin | Segment storage in data centres | Everything |
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
| Bottleneck | Fix |
|---|---|
| Outgoing bandwidth | Multi-tier CDN, ISP caches, efficient codecs (VP9, AV1) |
| Transcoding bursts | Queue + autoscaled workers; prioritise popular creators; GPU/ASIC encoders |
| Storage growth | Tiered storage: hot segments vs cold originals; drop unused renditions of old, unwatched videos |
| Metadata load | Sharded MySQL (Vitess) + heavy caching of video pages |
When things fail
| Failure | What happens |
|---|---|
| Transcoder crashes | The chunk job is retried; output is idempotent |
| CDN edge down | Clients fail over to another edge / regional cache |
| Upload interrupted | Resume from the last confirmed chunk |
| Origin region outage | Segments 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
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:
- 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.
- 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.
- 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.
- 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.
1. A creator's 10 GB upload over hotel Wi-Fi keeps failing near the end. What is the best design change?
Resuming means only the unconfirmed chunk is resent. A longer timeout doesn't help when the Wi-Fi itself drops.
2. Why must the transcoding pipeline split a video at keyframes rather than at exact one-minute marks?
A chunk starting mid-group would reference frames it doesn't have. Segments also start at keyframes, but that's a packaging rule, not the reason for the split.
3. A viewer's bandwidth drops from 8 to 1.5 Mbit/s while watching in 1080p. What does an adaptive bitrate player do?
Every rendition is already cut into aligned segments; the player simply asks for a different quality next. Nothing is re-encoded per viewer.
4. 1 billion hours watched a day at 3 Mbit/s. What is the average outgoing bandwidth, roughly?
1e9 × 3,600 s × 3 Mbit/s ÷ 86,400 s ≈ 125 Tbit/s ≈ 15 TB/s.
5. Why keep each original upload after transcoding has finished?
New codecs save bandwidth on every future view, which needs the best-quality source. Originals sit in cold storage until then.
6. Finance wants lower bandwidth costs. Which change saves the most for the least effort?
Popularity is skewed, so the expensive encode pays back only on videos with many views. Encoding everything in AV1 first would delay publishing and waste compute on unwatched videos.
7. A video goes viral, and its view count updates in jumps every few seconds and once even goes down. Why?
Counting through a stream avoids a hot row and protects against fake views; batch fraud checks can correct the total downwards later.
Score 60% or more and the lesson is marked complete.