How to design YouTube
The first sections are free. The deep dives, level expectations and quiz are part of Pro.
On this page
- The problem
- Clarifying questions
- The requirements menu
- Non-functional requirements
- Estimates
- Core entities
- The API
- The high-level design
- What breaks first
- The deep dives
- Entity fields
- Large, resumable uploads
- Transcoding and adaptive streaming
- Scaling metadata and hot videos
- Variants
- What each level is expected to show
- The 30-second answer
- Quiz
The problem
A video platform takes in uploads and plays them back on phones, browsers and televisions. The two paths look nothing alike: about a million uploads a day averaging 300 MB, some running to tens of GB, against a hundred million views a day that each fetch small pieces of a video. The answer turns on keeping those paths apart. Uploads go in resumable chunks straight to blob storage, an asynchronous pipeline cuts each video into short segments and transcodes them into several qualities with a manifest, and a CDN serves the segments so the backend handles one small metadata read per view.
Clarifying questions
| Ask | Why it matters | A typical answer |
|---|---|---|
How big are the uploads, and how many arrive a day? | The size decides whether a single request can carry a file at all, and the count decides how much transcoding capacity the pipeline needs. | About a million uploads a day. Videos average 300 MB, and some run to tens of GB, so an upload has to survive a dropped connection. |
How many views a day, and on which devices? | The view count sizes the metadata path, and the device list decides how many formats and resolutions the pipeline has to produce. | About a hundred million views a day, on web, mobile and smart TVs. |
Does playback need to adapt to the network, or is one fixed quality acceptable? | Adaptive playback means several renditions, short segments and a manifest; a fixed quality means a far simpler pipeline and a worse experience on a weak connection. | It has to adapt: a viewer on a train who keeps losing signal should keep watching, so the player must switch quality as bandwidth changes. |
How soon after upload must a video be watchable? | Transcoding a 300 MB file takes real time, so the answer decides whether processing is asynchronous with a visible status, or whether playback has to start before processing finishes. | The prompt doesn't fix a number. Assume minutes rather than seconds: processing runs in the background and the uploader sees a status until the video is ready. |
When something fails, do we prefer to keep serving or to be exactly right? | It tells you whether a slightly stale view count or a cached metadata record is acceptable in exchange for playback that stays up. | Availability wins. Our advice: keep play working while other parts are failing; metadata that lags by seconds is fine. |
How much does delivery cost matter? | Serving video is the biggest bill in this system, and a cost target changes what you encode up front and what you keep on the CDN. | It matters. Plan around a CDN bill of about $0.02 per GB served, and be ready to say what you'd change to halve it. |
Are search, comments, recommendations and moderation in scope? | Each is a system of its own, and the round is too short to carry them alongside the upload and playback paths. | No. Search, comments and view counts, recommendations, channels and subscriptions, and content moderation are all out of scope. |
Non-functional requirements
| Requirement | What it forces |
|---|---|
Uploads of tens of GB | The file shouldn't pass through the API servers, and sending it as one request means a drop loses all of it. The client sends it in chunks to blob storage with a presigned URL, and something has to remember which chunks arrived so a drop doesn't restart the upload. |
Playback starts fast, even on low bandwidth | The player needs a low-bitrate rendition to start on and short segments to switch between, served from an edge near the viewer. That means transcoding into several qualities before a video is marked ready. |
About 1 million uploads and 100 million views a day (Hello Interview) | Roughly 12 uploads and 1,160 views a second. Uploads are rare but each one carries hundreds of megabytes and minutes of CPU; views are constant and tiny. The two paths get separate components that scale on their own. |
Availability over consistency | Metadata can be cached and replicated with relaxed consistency: a view that reads a seconds-old record is fine. The one place this design insists on order is marking a video ready, which must happen after its segments and manifests exist. |
Low delivery cost: CDN bills at about $0.02 per GB (Alex Xu) | Video bytes are the dominant cost, so what gets encoded, where it is stored and what the CDN keeps all become cost decisions. Popular videos earn their place on the CDN; rarely watched ones don't. |
Estimates
| Quantity | Working | Result | What it sizes |
|---|---|---|---|
Parts in a 10 GB upload | 10 GB ÷ 5 MiB ≈ 1,900 parts (about 2,000); 10 GB ÷ 10 MiB ≈ 950 parts (about 1,000). S3 multipart allows up to 10,000 parts of 5 MiB to 5 GiB each, so parts at the 5 MiB minimum cover a file up to about 50 GB (10,000 × 5 MiB) before the client has to use bigger parts | 1,000 to 2,000 parts for a 10 GB file; parts at S3's 5 MiB minimum reach about 50 GB before the part size has to grow | The chunk size. Parts of 5 to 10 MiB (the interviewer's 5 to 10 MB, rounded up to S3's minimum) are small enough that a dropped connection loses little and large enough to stay within the part limit for the uploads this design plans for. |
Time to upload 10 GB on hotel wifi | Assume 20 Mbps upstream (an example figure, not a given): 10 GB = 80,000 Mb; 80,000 ÷ 20 = 4,000 s, about 67 minutes. One 10 MB chunk is 80 Mb; 80 ÷ 20 = 4 s | About 67 minutes for the file; about 4 seconds per 10 MB chunk | What one dropped connection costs: redoing the whole file is about an hour; redoing the chunk in flight is a few seconds. |
Upload bytes a day | 1 million uploads × 300 MB = 300 TB a day; 300 TB ÷ 86,400 s ≈ 3.5 GB/s, about 28 Gbit/s sustained | About 300 TB a day, 3.5 GB/s around the clock | Why upload bytes bypass the API servers: that stream flows directly into blob storage, and the service handles a few small calls per upload instead. |
Originals stored a year | 300 TB a day × 365 ≈ 110 PB a year at Hello Interview's upload rate; the alternative figure of 150 TB a day gives about 55 PB. Transcoded renditions come on top | Roughly 55 to 110 PB a year before any renditions | The storage side of the long tail: with viewing concentrated on a few videos, a large share of this volume sees few views, which is why rarely watched renditions belong on cheaper storage or aren't made until someone asks. |
Transcoding fleet (an example to show the method) | Assume one core spends about 30 minutes to produce all renditions of an average 300 MB video. 1 million × 30 min = 30 million core-minutes a day = 500,000 core-hours; ÷ 24 ≈ 20,800 cores busy all day. A burst at three times the average rate wants about 62,500 cores for its duration | About 20,800 cores at the average rate; about 62,500 during a threefold burst | How many transcoding workers to run. Sizing near the average and letting a queue hold the burst is far cheaper than sizing for the peak. |
Metadata reads landing on one viral video | 100 million views a day ÷ 86,400 ≈ 1,160 reads a second overall. If, as an example, 60% of the day's views are the viral video, about 700 reads a second hit the one partition that owns its id and about 460 are spread over everything else | About 700 reads a second on one partition, against 460 for the rest of the catalog | The hot partition. The total is modest; the trouble is where it lands. |
CDN bill at the view count, and what halving it saves | 100 million views × 300 MB = 30 PB a day if each view pulled a full average-sized video; 30 PB × $0.02 per GB = $600,000 a day. The alternative figure of 25 million views gives $150,000. Halving the serving cost at the larger figure saves about $300,000 a day | Up to about $600,000 a day; halving it is worth about $300,000 a day | The cost curveball. Real views pull one rendition's segments and often stop early, so this is an upper bound, but it shows why the long tail should not sit on the CDN. |
Core entities
| Entity | What it holds |
|---|---|
User | Whoever uploads or watches. Accounts are out of scope, so this stays a stub that videos point at. |
Video | The bytes: one original object in blob storage, then a set of segments per rendition once processing finishes. |
Video metadata | One row per video: who owns it, where processing stands, which upload chunks have arrived and where the manifest lives. |
Upload chunk | One entry per part of an in-flight upload; lives inside the metadata row or a side table keyed by video id. |
The API
| Endpoint | Notes |
|---|---|
| Creates the metadata row with status |
| The client calls this after each part lands. The service records the part and its ETag; before trusting it, it checks the part against the blob store's own list of uploaded parts. Idempotent, so a retried call after a drop is harmless. When the last part is in, the service completes the multipart upload. |
| The one backend call per view. Reads through the metadata cache; returns the primary manifest URL when status is |
The high-level design
Step 1 of 4
Uploads go straight to storage
Start with the write path. The client sends metadata to a stateless video service, which writes a row with status uploading and hands back a presigned URL for blob storage. The client then sends the video bytes to storage directly, in multipart chunks, and reports each part to the service, which records it in the metadata row. Nothing heavy passes through the service: at a million uploads a day of 300 MB, the raw stream is about 3.5 GB/s, and that goes to blob storage rather than to your servers.
What breaks first
The deep dives
Large, resumable uploads. Someone is uploading a file of tens of GB over hotel wifi and the connection drops halfway. What does the client send when it reconnects, what does each side have to remember, and what does the drop cost?
Transcoding and adaptive streaming. A viewer on a train keeps losing signal and the video should keep playing. What did the pipeline produce from the upload, how does the player use it, and what changes when the serving bill has to be cut in half?
Scaling metadata and hot videos. One video goes viral overnight and most of the day's views ask for it. What does each part of the design see, where does the load concentrate, and what stops a viewer from being handed a video that isn't fully there?
Concepts this guide uses
Sources
- Alex Xu, System Design Interview, chapter 15: Design YouTube (book notes on books.dwf.dev)
- ByteByteGo: Design YouTube (System Design Interview course)
- Amazon S3 User Guide: Multipart upload limits
- Apple Developer: About HTTP Live Streaming
- Amazon S3 Developer Guide: Configuring Amazon S3 event notifications