Design YouTube
Understanding the Problem
📺 What is YouTube? YouTube is a video sharing platform. Anyone can upload a video, and anyone can watch it on almost any device and any network, from a phone on a train to a 4K TV on fiber. Under the hood it is two systems glued together: an upload and processing pipeline that turns one large source file into many small, streamable pieces, and a delivery system that gets those pieces to viewers fast.
You will also be asked to "design Udemy" or "design a course video platform." It is the same problem with a different business model. Instructors upload lectures, the platform transcodes them, and students stream them with adaptive quality. The differences are that the videos are paid for, so we have to stop people from sharing a link to them, and that progress through a course matters more than it does on YouTube. We'll cover both in the deep dives.
Functional Requirements
Start by agreeing with your interviewer on what users do. YouTube has a huge surface area (comments, subscriptions, recommendations, live, ads), so be explicit that we're designing the video pipeline itself.
Core Requirements
- Users should be able to upload videos, including large ones (several GB).
- Users should be able to watch videos, with playback that adapts to their device and network.
- Users should be able to resume a video where they left off, on any device.
Below the line (out of scope)
- Search, recommendations and the home feed.
- Comments, likes and subscriptions.
- Live streaming (see /system-design/live-streaming).
- Ads and monetization.
Non-Functional Requirements
Ask your interviewer for the scale. We'll assume 1 billion daily active viewers watching about 5 videos a day, and 1 million new uploads a day, with an average source file of around 500 MB.
Core Requirements
- The system should support uploads of up to tens of GB, and survive flaky connections without starting over.
- Videos should start playing within about a second, and rebuffer rarely, on networks from 1 Mbps to 100+ Mbps.
- The system should handle on the order of 60k video starts per second on average and serve tens of terabits per second of video.
- The system should be highly available for playback. A new upload can take minutes to become watchable (eventual consistency is fine there).
- Uploaded videos must never be lost (high durability).
Below the line (out of scope)
- Content moderation and copyright matching (an async step we'll mention but not design).
- DRM for studio content. We'll touch on protecting paid course videos.
Now the math, because it decides where the hard parts are.
- Uploads: 1M videos × 500 MB = 500 TB of raw video a day, about 6 GB/s or roughly 50 Gbps of ingest. After transcoding into several resolutions and a couple of codecs, total new storage is on the order of 1 PB a day.
- Video starts: 1B × 5 = 5B views a day, or about 58k per second on average.
- Egress: say a view lasts 5 minutes at an average 3 Mbps. That's 3 Mbps × 300 s ÷ 8 ≈ 112 MB per view, and 5B × 112 MB ≈ 560 PB a day. Divide by 86,400 seconds and you get about 6.5 TB/s, or around 50 Tbps on average, roughly double that at peak.
The metadata side of this problem (titles, view pages, 58k reads a second) is a normal caching exercise. The egress number is the one that matters. No fleet of application servers or single object store serves 100 Tbps. This design only works if almost every byte of video comes from a CDN close to the viewer, and the rest of the design should be built to make that true.
The Set Up
Planning the Approach
We'll build the upload path first, then processing and playback, then resume. The deep dives cover the things an interviewer will push on: transcoding speed, resumable uploads, adaptive streaming, CDN delivery, and protecting paid content.
Defining the Core Entities
- Video: the logical video. Owner, title, description, status (
UPLOADING,PROCESSING,READY,FAILED), duration and a pointer to its manifest. - Source File: the original upload, stored as-is in object storage. We keep it forever so we can re-encode later with better codecs.
- Rendition: one encoded version of the video, for example 720p H.264 at 2.8 Mbps. Each rendition is cut into short segments of a few seconds.
- Manifest: a small text file that lists the renditions and their segments. The player reads it to know what it can fetch.
- Watch Progress: the last position a user reached in a video, keyed by
(userId, videoId).
API or System Interface
POST /videos
{ title, description, sizeBytes, contentType }
-> { videoId, uploadId, partSize, partUrls: [ ... ] } // pre-signed URLs for each part
POST /videos/{videoId}/upload-complete
{ uploadId, parts: [ { partNumber, etag } ] }
-> 202 { status: "PROCESSING" }
GET /videos/{videoId}
-> { title, description, status, durationSec, manifestUrl, resumeAtSec }
PUT /videos/{videoId}/progress
{ positionSec, clientTs }
-> 204
The video bytes never go through our API. The client uploads them straight to object storage with pre-signed URLs, and the player downloads them straight from the CDN with the manifestUrl. Our servers only ever handle small JSON.
High-Level Design
1) Users should be able to upload videos
The obvious first version is a POST /videos with the file in the body. The Video Service receives it and writes it to object storage. That works for a 20 MB clip, but it's wrong at our scale. A 5 GB file ties up an app server connection for many minutes on a slow uplink, our servers have to buffer or stream gigabytes they do nothing with, and if the connection drops at 95% the user starts over.
Instead, the client asks the Video Service for permission to upload, and then talks to object storage directly:
- The client calls
POST /videos. The Video Service writes a Video row with statusUPLOADING, starts a multipart upload in S3 (or GCS), and returns a set of pre-signed URLs, one per part. - The client uploads the parts in parallel, straight to S3, using those URLs. Each URL is only valid for that one part and for a limited time.
- When all parts are in, the client calls
upload-completewith the part ETags. The Video Service completes the multipart upload and moves the video toPROCESSING.
S3 gives us durability (it's designed for eleven nines) and effectively unlimited capacity, so we don't build our own blob store for this. The metadata is small: 1M new rows a day at a few KB each is a few GB a day, which a sharded Postgres (or a wide-column store like Cassandra) handles easily. We shard by videoId, because almost every query is "get this video."
2) Users should be able to watch videos
The simplest playback is to hand the client a URL to the original file. The browser downloads an MP4 and plays it as it arrives. This has three problems:
- One size fits nobody. The source is often a 4K file at 20+ Mbps. A phone on 3G can't play it, and a phone screen doesn't need it.
- Codec support varies. The uploader's camera may produce a codec the viewer's device can't decode.
- No adaptation. If the network slows down halfway through, the player can only stall.
So we transcode every upload into a set of renditions, an encoding ladder, and cut each one into segments a few seconds long:
| Rendition | Resolution | Typical bitrate (H.264) |
|---|---|---|
| 240p | 426×240 | 0.3-0.4 Mbps |
| 360p | 640×360 | 0.7-1 Mbps |
| 480p | 854×480 | 1.2-1.5 Mbps |
| 720p | 1280×720 | 2.5-3.5 Mbps |
| 1080p | 1920×1080 | 4.5-6 Mbps |
| 4K | 3840×2160 | 15-20 Mbps |
Newer codecs (VP9, AV1) get the same quality at noticeably lower bitrates, at the cost of much more encoding CPU. We usually produce H.264 for every video because everything can play it, and add VP9 or AV1 for videos that get enough views to pay back the encoding cost.
Then we write a manifest that describes the ladder. With HLS it's a master playlist pointing at one media playlist per rendition:
#EXTM3U
#EXT-X-STREAM-INF:BANDWIDTH=800000,RESOLUTION=640x360,CODECS="avc1.4d401e,mp4a.40.2"
360p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=2800000,RESOLUTION=1280x720,CODECS="avc1.4d401f,mp4a.40.2"
720p/index.m3u8
#EXT-X-STREAM-INF:BANDWIDTH=5000000,RESOLUTION=1920x1080,CODECS="avc1.640028,mp4a.40.2"
1080p/index.m3u8
DASH does the same thing with an XML file (an MPD). With fragmented MP4 (CMAF) segments, the same media files can be referenced from both an HLS and a DASH manifest, so we store the segments once.
The pipeline: when S3 reports the upload is complete, an event lands on a transcode queue. Workers pull jobs, read the source, produce the renditions and segments, write them to a separate bucket, write the manifest last, and mark the video READY.
Playback is then mostly static file serving. The client calls GET /videos/{id}, which returns metadata and the manifest URL from a cache in front of the metadata DB. The player fetches the manifest and segments from a CDN, which pulls from the segment bucket on a cache miss.
A single queue and a pool of workers that each transcode one whole video is too slow for long videos. We'll fix that in the deep dives.
3) Users should be able to resume where they left off
The player reports its position with PUT /videos/{id}/progress, and GET /videos/{id} returns resumeAtSec for the signed-in user.
This looks trivial until you do the math. With 1B viewers each watching about an hour a day, the average number of people watching at once is 1B × 60 ÷ 1,440 ≈ 42 million. If every player reports every 10 seconds, that's over 4M writes a second for a feature nobody notices until it breaks.
Three choices keep it manageable:
- Report less often. Every 30-60 seconds, plus on pause, seek, and when the tab closes or the app is backgrounded. Losing the last 30 seconds of position is fine. That drops us to around 1M writes a second.
- Use a store built for writes. Cassandra or DynamoDB, keyed by
(userId, videoId), last write wins. These are tiny, independent rows with no transactions, which is exactly what those stores are good at. - Don't read-modify-write. Each update is a blind upsert with the client timestamp, and we keep the row with the later timestamp, so a stale report from an old tab can't overwrite a newer one.
A Progress Service sits in front of the store. It's stateless, so it scales horizontally.
Potential Deep Dives
1) How do we make transcoding fast, so a long video is watchable soon after upload?
A one-hour 4K upload transcoded into six renditions on one machine can take longer than an hour. Uploaders expect to see their video live in minutes.
Bad Solution: One Worker per Video, Sequentially
Approach
A worker pulls the job, decodes the source once, and encodes each rendition in turn.
Challenges
Encoding time grows with video length, and one machine's cores are the ceiling. A single failure near the end (a preempted instance, a bad frame) throws away an hour of work. Long videos also block the queue for short ones unless we add priorities.
Good Solution: Parallelize by Rendition
Approach
Fan the job out: one task per rendition, each on its own worker. The 240p and 1080p encodes run at the same time.
Challenges
It helps, but only by the number of renditions, and the slowest rendition (4K) is still one long task over the whole video. Every worker also has to download and decode the entire source.
Great Solution: Split into Chunks and Run a DAG
Approach
Split the source into chunks of, say, 10-30 seconds, always at keyframe (GOP) boundaries so each chunk can be decoded on its own. Then every (chunk, rendition) pair is an independent task. A one-hour video cut into 20-second chunks is 180 chunks × 6 renditions = 1,080 small tasks that can all run at once across the worker fleet. The wall-clock time drops from hours to roughly the time it takes to encode one chunk, plus the split and packaging steps.
The whole job is a DAG:
- Validate and probe the source (duration, codecs, resolution). Reject garbage early.
- Split into chunks.
- Encode each chunk into each rendition (the wide, parallel step).
- Package: concatenate or directly segment the encoded chunks into HLS/DASH segments and write the media playlists.
- Side branches in parallel: extract audio, generate thumbnails, produce captions with speech-to-text, run moderation and copyright checks.
- Write the master manifest and flip the video to
READY.
An orchestrator tracks the DAG's state (a workflow engine like Temporal, AWS Step Functions, or a small service that stores task state in a database and enqueues ready tasks). Each task is idempotent: its output path is deterministic, like videos/{id}/720p/chunk_0042.mp4, so a retried task just overwrites the same file. A failed task is retried on its own instead of failing the whole video.
Two more tricks make the video available sooner:
- Publish low renditions first. Mark the video watchable as soon as 360p and 720p are done, and add the higher renditions to the manifest as they finish.
- Prioritize. Short videos and popular channels go into a higher-priority queue, and the bulk re-encode of old videos into AV1 runs on cheap spot capacity in the background.
Challenges
Chunk boundaries can show tiny quality differences, because each chunk's encoder starts with no knowledge of the previous one. Splitting only at keyframes and using constrained bitrate settings keeps that invisible in practice. The orchestrator is now a critical component that needs its own durability, which is why a proven workflow engine is a better choice than a homegrown one.
If your interviewer asks why we don't just transcode on upload, point out that transcoding is the most compute-hungry thing in the system by far. Everything else is serving files. Making it a queue-driven, chunked, retryable pipeline is what lets it run on cheap, preemptible machines.
2) How do we handle large uploads on unreliable connections?
A creator on hotel Wi-Fi uploading a 10 GB file will lose the connection at some point.
Bad Solution: A Single PUT
Approach
One pre-signed URL, one HTTP request with the whole file.
Challenges
Any drop means starting from zero. S3 also caps a single PUT at 5 GB, so very large files can't even be sent this way.
Great Solution: Multipart Upload with Resume
Approach
Use the object store's multipart upload. With S3, each part is between 5 MB and 5 GB, and an upload can have up to 10,000 parts. The client:
- Splits the file into parts (say 16 MB each).
- Uploads 4-6 parts in parallel, each to its own pre-signed URL, keeping each part's ETag.
- On a failure, retries just that part.
- If the app restarts, calls the Video Service for the upload's state. The service asks S3 which parts it already has (
ListParts) and returns fresh URLs for only the missing ones. - Calls
upload-completewith the part list once all parts are done.
The client can send a checksum with each part, and S3 verifies it on arrival, so a corrupted part is rejected instead of silently breaking the video.
We also clean up. A lifecycle rule aborts multipart uploads that haven't completed after a few days, otherwise abandoned parts sit in the bucket and cost money forever.
Challenges
Pre-signed URLs expire, so a long upload has to fetch new ones. Doing it in batches of parts as the upload proceeds is simpler than issuing all 10,000 at the start. If you want a standard protocol rather than the S3 API, the open tus protocol does the same thing over plain HTTP.
3) How does the player adapt to changing network conditions?
This is adaptive bitrate streaming (ABR), and it's mostly a client-side algorithm on top of the segments we produced.
Every rendition is cut at the same timestamps, with segments of the same length (2-6 seconds is typical), each starting with a keyframe. That means the player can switch rendition at any segment boundary: play segment 41 at 1080p and segment 42 at 480p, and the picture continues seamlessly.
The player keeps a buffer of downloaded-but-not-yet-played video, often 10-30 seconds for on-demand content. Before each segment request, it decides which rendition to fetch:
- Throughput-based: measure how fast recent segments downloaded and pick the highest rendition that fits under, say, 80% of that.
- Buffer-based: if the buffer is healthy, step up; if it's draining, step down, regardless of the last throughput sample.
- Real players combine both, and also cap the rendition at the screen size. A 1080p stream in a 400-pixel-wide embedded player wastes bandwidth.
Startup time is a separate problem from steady-state quality. To start fast:
- Return the manifest URL in the same response as the video metadata, so the player doesn't need an extra round trip.
- Start on a modest rendition (360p or 480p) and step up once the player has a throughput estimate.
- Keep the first segments small and make sure they're likely to be cached at the edge.
It's common to describe ABR as "the server picks the right quality." It's the other way round. The server just publishes every option as plain files on a CDN, and the client decides, segment by segment. That's why the delivery side scales: it's stateless static file serving.
4) How do we serve 50-100 Tbps of video?
Bad Solution: Serve from Object Storage
Approach
Point players at the segment bucket directly.
Challenges
Every byte crosses the internet from one region, so viewers far away get high latency and low throughput, and the egress bill is enormous. Object storage also isn't built to serve the same hot object to hundreds of thousands of clients at once.
Good Solution: A CDN in Front of the Bucket
Approach
Put a CDN in front, with the bucket as its origin. Segments are immutable (a new encode gets a new path), so we can cache them with a very long TTL. The manifest gets a shorter TTL, since we may add renditions to it.
Challenges
Video popularity is extremely skewed. A small fraction of videos gets most of the views and stays hot at every edge. But the long tail is enormous: millions of videos each watched a few times a day. Each of those is a cache miss at whichever edge the viewer hits, and with hundreds of edge locations, a lot of misses go back to the origin.
Great Solution: Tiered Caching and Popularity-Aware Placement
Approach
- Origin shield / mid-tier. Edge caches miss to a small number of regional caches, not to the bucket. A long-tail video requested from 50 different edges is fetched from the origin once per region instead of 50 times.
- Push the head, pull the tail. For videos that are clearly about to be popular (a big channel's new upload, something trending), pre-warm the first segments at the edges. Everything else is pulled on demand.
- Cache the beginning harder than the end. Many viewers leave in the first minute. The first segments of a video are requested far more often than the last ones, so they're the most valuable to keep at the edge.
- Multiple CDNs or your own. At this scale, large platforms often run their own edge caches inside ISP networks, alongside commercial CDNs. The client or a steering service picks a CDN per session. (Netflix's version of this is covered in /system-design/netflix.)
Challenges
More cache tiers add latency on a miss, and you need to watch hit ratios per tier to know where to add capacity. It's worth saying that the CDN is a buy-not-build decision for almost every company, and only the very largest video platforms build their own.
5) How do we protect paid course videos, Udemy-style?
On YouTube, a public video is meant to be shared. On a course platform, only enrolled students may watch, and a shared link is lost revenue. The pipeline (upload, chunked transcode, HLS) is the same; what changes is access control and progress.
Bad Solution: Check Access Only on the Page
Approach
The course page checks enrollment and only then shows the player.
Challenges
The segment URLs are plain CDN URLs. Anyone who opens the browser's network tab can copy the manifest URL and share it, and it works for everyone, forever.
Good Solution: Signed URLs or Signed Cookies
Approach
The Video Service checks enrollment, then returns a manifest URL signed with a short expiry (say an hour) and scoped to that video. Because a manifest references hundreds of segments, a signed cookie scoped to the video's path (/courses/123/lecture/7/*) is easier than signing every segment URL. The CDN checks the signature at the edge, so the origin never sees unauthorized requests, and cached segments stay cacheable for everyone who's authorized.
Challenges
A shared link stops working after an hour, but the segments themselves are unencrypted. Anyone with access can download them with a tool and re-upload the course elsewhere.
Great Solution: Encrypted Segments with a License or Key Server
Approach
Encrypt the segments at packaging time. For a basic level of protection, HLS supports AES-128 encryption, with the key URL listed in the playlist. The key server checks the student's session and enrollment before handing out the key. For stronger protection (studio content, premium courses), use DRM: Widevine, FairPlay and PlayReady, with the device's secure decoder fetching a license from a license server. With CMAF and the cbcs encryption scheme, one encrypted copy of the segments can be used with all three.
Challenges
Every playback now needs a key or license request, which is a new dependency in the startup path, so the license server has to be fast and highly available. DRM also adds device compatibility work. Be honest with your interviewer that nothing stops a determined pirate with a screen recorder. The goal is to make casual sharing and bulk downloading not worth it.
Course platforms also need more from progress than resume. "Lecture complete" (say, 90% watched) drives the course progress bar and certificates, so the Progress Service emits a lecture_completed event when a report crosses the threshold, and a course progress table is updated from that event. That record matters to the student, so unlike resume position, it's stored in a durable relational table, but it's written once per lecture, not every 30 seconds.
Final Design
The main flows:
- A creator calls
POST /videos, gets a video ID and pre-signed part URLs, uploads the file in parallel parts straight to object storage, and callsupload-complete. - The upload event starts a transcode DAG: probe, split at keyframes, encode every chunk into every rendition in parallel, package into HLS/DASH segments, generate thumbnails and captions.
- When the low renditions are ready, the video is marked
READYin the metadata DB and becomes watchable. Higher renditions are added to the manifest as they finish. - A viewer calls
GET /videos/{id}and gets metadata, the manifest URL and their resume position, served from cache. - The player streams segments from the CDN, which misses to a regional shield and then to the segment bucket. It picks a rendition per segment based on throughput and buffer.
- While playing, the client reports progress every 30-60 seconds to the Progress Service, which upserts it into Cassandra.
What is Expected at Each Level?
Mid-level
You should separate metadata from video bytes, upload to object storage with pre-signed URLs, and serve video through a CDN. You should know that videos are transcoded into several resolutions, and with a little prompting explain segments and why they let the player switch quality. A queue between upload and transcoding should come up naturally.
Senior
You should do the egress math and use it to justify the CDN-first design. Expect to explain multipart, resumable uploads; chunked, parallel transcoding at keyframe boundaries with idempotent, retryable tasks; and how ABR works on the client. You should have an answer for progress tracking at tens of millions of concurrent viewers, and for keeping paid videos private with signed URLs or cookies.
Staff+
You should talk about cost and trade-offs as much as components: when an extra codec is worth its encoding cost, how the popularity curve shapes caching (shield tiers, pre-warming the head, caching the start of videos), and when to run your own edge caches. You should design the transcode pipeline for operations: priorities, spot capacity, re-encoding the back catalog, and how a bad encoder release is detected and rolled back. Bringing up the DRM and license-server availability trade-off for paid content, without being asked, is a strong signal.