Design YouTube
hard 45 minAnyone may upload a video, and anyone may watch it on any screen.
Video lesson · Chapter 1 of 6
Protect the original upload
One film, many sizes, in 90 seconds
1:30Reel coming soon
Theory
Read or listen first. About 2 min.
What it is
A video sharing service takes a file from any person, turns it into versions that every phone, computer and television can play, and shows it to anyone who asks.
Two very different systems share one database of titles. The upload side is a factory: slow, heavy and allowed to wait. The watch side is a shop window: quick, enormous and never allowed to wait for the factory.
Why it exists
A file from a camera is a poor thing to send. It may be too large for a phone network, in a format that a television cannot read, and impossible to start in the middle. So the service makes copies in several qualities, each cut into pieces of a few seconds.
Bytes decide everything. Our assumed 500 million hours of watching a day is about 83 Tb/s on average, and no single building sends that.
A short history
2010
Vitess begins inside YouTube to spread MySQL over many machines, by its own project history. It is open source today.
August 2017
RFC 8216 publishes HTTP Live Streaming: short media files and text playlists that any HTTP cache can keep.
April 2021
A YouTube engineering article and an ASPLOS paper describe the VCU, a chip made for transcoding in data centers.
June 2022
RFC 9110 becomes the HTTP standard and includes range requests, which RFC 7233 described before.
Words to know
- Codec
- The method that compresses and opens the picture, such as H.264, VP9 or AV1.
- Transcoding
- Decoding a video and encoding it again in another size, bitrate or codec.
- Rendition
- One finished quality of a video, for example 720p at 2.5 Mb/s.
- Ladder
- The list of renditions from lowest to highest.
- GOP
- Group of pictures. It starts with a complete picture. A closed one can be decoded alone.
- Segment
- A few seconds of one rendition as a file.
- Manifest
- The text that lists renditions and segments (.m3u8 in HLS, .mpd in DASH).
- ABR
- Adaptive bitrate: the player picks a rendition for each segment.
Solve it like an interview
New to it? Start with Approach. Revising? Go straight to the mock.
- 1ApproachWhat this question tests, where it gets hard, and how to spend the time.
- 2ScopeAsk what changes the design, then commit to a short list.
- 3NumbersWork out a number when the answer changes what you build.
- 4API and dataThe contract first, then the data that serves it.
- 5DesignStart with the smallest system that works. Change it only when something breaks.
- 6Deep divesCompare the options before you open them, then say which you would pick.
- 7Explain your choicesAnswer first. Then compare your reasoning.
- 8By levelThe same question is judged differently for mid, senior and staff.
- 9MockAnswer against the clock, then score yourself.
Understand it
Picture it
The flip-book workshop
Copy once in the workshop, then read from the nearest shelf, one part at a time.
Scope
What are we building?
A service like YouTube: upload, processing, watching, search, likes, comments and subscriptions. This is an exercise with our own assumptions, not a description of the company's system.
Take it in
Huge files over poor networks, without starting again.
Make copies
600,000 busy cores at our scale, fed by a queue.
Send it
250 Tb/s at peak, nearly all from caches.
Count it
Two million events a second, and one video may be very hot.
Similar services
The finished system
Where the design ends up
The whole system
Read next
Who owns which idea
| Idea | Its own page |
|---|---|
| Resumable and direct uploads | File upload APIs |
| Objects, parts, storage classes | Object storage |
| Edges, shields, keys | CDN, CDN design |
| Building a CDN | Content delivery network |
| Hot counters | Sharded counters |
| Candidates and ranking | Recommendation system |
| Suggestions while typing | Search autocomplete |
| Jobs, retries, duplicates | Queues, Idempotency |
| Telling subscribers | Notification service |
For the interview: Approach, then Scope, Numbers, API and data, Design and Deep dives. For revision, go to the Mock.
Summary
The whole topic in one minute.
The file goes straight from the creator to object storage in parts that can be resumed. A job queue hands it to workers, which cut it at GOP borders, encode the pieces in parallel and write segments and a manifest. The video is published when a low rung is ready, and better rungs join later.
Viewers get the title from a small sharded database with a cache, and the bytes from a CDN. The player changes quality between segments. Views are events in a log and become numbers a little later.
- Files never pass through our API servers.
- Split at GOP borders, encode in parallel, retry one piece and not the film.
- Publish with the low rungs, add the rest later.
- All renditions are cut at the same times, so the player can switch between them.
- Bytes come from caches; the database only holds small rows.
- Views are events first and numbers later.
Sources
- YouTube Help: upload limits
- YouTube Data API: resumable uploads
- YouTube: new era of video infrastructure (VCU)
- Warehouse-scale video acceleration (ASPLOS 2021)
- Vitess: history
- Google Global Cache introduction
- YouTube Help: how metrics are counted
- RFC 8216: HTTP Live Streaming
- RFC 9110: HTTP semantics (range requests)
- Amazon S3: multipart upload limits
- tus: resumable upload protocol