Over a billion hours of YouTube are watched every day, often on mobile data that changes from 4G to 3G as a train moves. “Design YouTube” or “design Netflix” is a frequently reported question at Google, Netflix and Amazon. Two ideas carry the whole design: do the heavy work once (transcode at upload time) and let the player adapt (adaptive bitrate from a nearby CDN).
Step 1 · Requirements
- Functional: upload videos; watch them on any device; search and browse (title, thumbnail, channel); count views; likes and comments.
- Non-functional: playback starts fast and rarely freezes; works on slow networks; uploads survive flaky connections; huge scale and global reach; cost-efficient storage and bandwidth.
- Out of scope (say it): recommendations, live streaming, ads, copyright matching.
Step 2 · Estimates
- Uploads: say 500,000 hours of video uploaded a day. One hour of 1080p is ~2–3 GB; with all versions, roughly 5 GB stored per hour → ~2.5 PB a day. Storage cost is a real design driver.
- Watching: reads hugely outnumber uploads. If 100 million viewers watch at 3 Mbps at once, that's 300 Tbps, which only a CDN can deliver.
- Long tail: a small fraction of videos get most views. Keep popular ones on CDN edges; old, rarely watched ones can move to cheaper storage.
Step 3 · API
POST /videos { title, description } → { videoId, uploadUrl } // pre-signed, resumable
PUT <uploadUrl> (file chunks, straight to object storage)
GET /videos/{id} → { title, channel, thumbnails, manifestUrl, status }
GET <cdn>/videos/{id}/master.m3u8 → list of qualities → each lists its 4-second segmentsStep 4 · Design
Upload and processing
- Resumable upload: send the file in chunks straight to object storage; if the network drops, continue from the last chunk.
- Transcoding as a DAG: split → encode each chunk into each resolution (thousands of small parallel jobs) → merge → package into HLS/DASH segments → thumbnails. Workers pull jobs from a queue and scale with load.
- Status: the video row moves from uploading → processing → ready; the creator gets a notification when it's live.
Playback: adaptive bitrate
The player first downloads a manifest listing available qualities and their segments, then fetches segments one by one, measuring download speed and picking the next segment's quality to keep a few seconds of video buffered:
🎮 Watch a video on a bumpy network
Turn adaptive bitrate off on the train journey: the player keeps fetching 1080p it can't download in time, so it freezes. With ABR on, quality dips for a few seconds and the video keeps playing. That's the choice YouTube and Netflix make.
| Quality | Typical bitrate | 1 hour uses | Good for |
|---|---|---|---|
| 240p | ~0.4 Mbps | ~180 MB | Weak mobile signal |
| 480p | ~1.2 Mbps | ~550 MB | Phones on 3G/4G |
| 720p | ~2.5 Mbps | ~1.1 GB | Phones, laptops |
| 1080p | ~5 Mbps | ~2.3 GB | Laptops, TVs on Wi-Fi |
Metadata and the rest
- Metadata DB: videos (id, title, channel, status, durations, manifest URL), channels, comments. Read-heavy: cache video pages and thumbnails.
- Thumbnails: small images, requested constantly, so serve them from the CDN.
- Search: a separate search index over titles, descriptions and captions.
Step 5 · Scale and reliability
- CDN first: popular segments live at edge servers near viewers. Netflix places its own Open Connect caching servers inside internet providers' networks and pre-fills them at night with what people are likely to watch.
- Storage tiers: hot videos on fast storage and CDN; old, rarely watched videos on cheaper cold storage; maybe drop rarely used versions and re-create them on demand.
- View counts: stream view events into a queue, count in memory, write aggregates periodically, and filter bots. Exact real-time counts aren't needed.
- Start time: short first segments, a lower first quality, and pre-fetching the start of likely next videos.
- Cost: newer codecs (like AV1) cut bandwidth for the same quality but cost more CPU to encode, a good trade for popular videos.
🧠 PATH memory card
Remember the video streaming design for good
Picture it · Anchor it · Trace it · Hit-recall it. Four quick steps that turn “I read it once” into “I can explain it in an exam”.
- P
Picture it
Your brain remembers scenes far better than definitions.
← swipe to see the whole picture →
A film is shot once, then the lab makes several prints, from a light, low-quality copy to a sharp big-screen one, each cut into short reels and sent to cinemas in every town. In your seat, the projector picks a sharper or lighter reel every few seconds depending on how fast the reels are arriving.
- A
Anchor it
A silly sentence you can't forget, where every word maps to the concept.
“Upload once, encode many, cut into chunks, serve near”
- Upload once→Resumable upload straight to object storage
- Encode many→Transcoding pipeline → bitrate ladder (240p…4K)
- Cut into chunks→HLS/DASH segments + manifest
- Serve near→CDN edge servers close to viewers
- Seat picks the reel→Adaptive bitrate per segment
- T
Trace it
Run it by hand on a tiny example once. Doing beats reading.
Creator uploads a 10-minute 1080p video in 5 MB chunks → object storage → queue → split into 20 chunks → 4 resolutions × 20 = 80 parallel encode jobs → packaged into 4-second segments → status ready. A viewer on a train presses play: manifest → first segment at 480p → speed looks good → 720p → tunnel, speed drops → 240p for two segments → back to 720p. No freezing. - H
Hit-recall it
Test yourself now, then again on the day each card comes back.
Card 1 / 8 · new0 mastered · 0 practisedSay the answer out loud first, then flip and be honest.
Follow-up questions interviewers ask
- “Live streaming?” Same segments-and-manifest idea, but encoding happens in real time and segments are a second or two long to keep delay low.
- “Resume where I left off?” Save the playback position every few seconds per user and video; it's a small, write-heavy key-value table.
- “Region restrictions?” Check the viewer's region before handing out the manifest; CDN URLs can be signed and expire.
Where to go next
Video uploads are big files written once. What about files you edit all the time, on three devices? Next: design Google Drive or Dropbox.
Key takeaways
- ✓Upload straight to object storage with resumable, pre-signed uploads.
- ✓Transcode once into a bitrate ladder, in parallel, via a queue of jobs.
- ✓Cut videos into short segments with a manifest (HLS/DASH).
- ✓Serve segments from a CDN; the player adapts quality per segment.
- ✓Cache metadata and thumbnails; count views asynchronously; tier storage by popularity.
Frequently asked questions
How does YouTube store and stream videos?
An uploaded video is saved to object storage, then a transcoding pipeline converts it into many versions (for example 240p to 4K, in several formats) and cuts each into short segments of a few seconds. The segments are stored and copied to CDN servers around the world. When you press play, your player downloads a manifest listing the versions and fetches segments from the nearest CDN server, switching quality as your network changes.
What is transcoding?
Transcoding converts a video from the format it was uploaded in into other formats, resolutions and bitrates. One upload becomes a 'ladder' of versions, such as 240p for weak mobile connections up to 1080p or 4K for fast Wi-Fi, so every viewer gets a version their device and network can play smoothly.
What is adaptive bitrate streaming?
Adaptive bitrate (ABR) streaming means the video player measures your download speed and picks the quality of each next segment to match: high quality when the network is fast, lower quality when it slows, so the video keeps playing instead of freezing. HLS and MPEG-DASH are the common protocols; both use a manifest file and short segments.
Why do YouTube and Netflix use CDNs?
Video is the heaviest traffic on the internet. Serving it from a few central data centres would be slow and expensive. CDNs keep copies of popular segments on servers close to viewers, often inside internet providers' networks, so videos start quickly and long-distance network costs drop. Netflix runs its own CDN, called Open Connect, with caching servers placed at internet providers.
How are YouTube view counts handled at scale?
Writing to a database row for every view of a viral video would create a massive hot spot. Instead, view events go to a stream or queue, are counted in memory and aggregated in batches, then written periodically. The number you see can lag slightly, which is an acceptable trade-off; views are also filtered for spam and bots before they count.
🧠 Quick check: video streaming
1. Why cut videos into segments of a few seconds?
2. A viewer's network drops from 6 Mbps to 1 Mbps mid-video. With ABR, what happens?
3. Where should a 2 GB upload go?
4. Transcoding a long 4K video takes hours on one machine. How do you speed it up?
Checking your access…