YouTube#
Problem statement (interviewer prompt)
Design YouTube: resumable video upload from creators, multi-resolution + multi-codec transcoding, global CDN delivery with adaptive bitrate, recommendation-driven discovery, comments, live streaming, and copyright (Content ID). Handle 500h of video uploaded per minute.
flowchart LR
U([Creator])
UP[Upload Service]
S3[(Origin Storage)]
TR([Transcoder])
CDN
META[(Metadata DB)]
V([Viewer])
REC([Recommendations])
U --> UP --> S3 --> TR --> CDN
UP --> META
V --> CDN
V --> REC
REC --> META
classDef client fill:#dbeafe,stroke:#1e40af,stroke-width:1px,color:#0f172a;
classDef edge fill:#cffafe,stroke:#0e7490,stroke-width:1px,color:#0f172a;
classDef service fill:#fef3c7,stroke:#92400e,stroke-width:1px,color:#0f172a;
classDef datastore fill:#fee2e2,stroke:#991b1b,stroke-width:1px,color:#0f172a;
classDef cache fill:#fed7aa,stroke:#9a3412,stroke-width:1px,color:#0f172a;
classDef queue fill:#ede9fe,stroke:#5b21b6,stroke-width:1px,color:#0f172a;
classDef compute fill:#d1fae5,stroke:#065f46,stroke-width:1px,color:#0f172a;
classDef storage fill:#e5e7eb,stroke:#374151,stroke-width:1px,color:#0f172a;
classDef external fill:#fce7f3,stroke:#9d174d,stroke-width:1px,color:#0f172a;
classDef obs fill:#f3e8ff,stroke:#6b21a8,stroke-width:1px,color:#0f172a;
class U,V client;
class UP service;
class META datastore;
class TR,REC compute;
class S3 storage;
flowchart TB
subgraph Creator
APP([Creator app / Studio])
end
subgraph Upload[Upload Pipeline]
PRE[Resumable upload<br/>chunked - tus / GCS]
OBJ[(Origin: Colossus / S3)]
META[(Video metadata)]
QUE[[Transcode jobs queue]]
end
subgraph Transcode[Transcode Farm]
SPLIT[Chunked by GoP /<br/>shot boundary]
ENC([Encoders<br/>H.264 / VP9 / AV1 ladders])
AUD([Audio encoder<br/>AAC / Opus])
SUB([Auto captions / ASR])
THUMB[Thumbnail extractor]
PACK[HLS / DASH packager]
DRM[DRM: Widevine / FairPlay / PlayReady]
end
subgraph Distribution
EDGE[YouTube CDN<br/>Google Edge / ISP peering]
GGC[Google Global Cache<br/>inside ISP]
ABR([Adaptive Bitrate selector<br/>client side])
end
subgraph Discovery
HOME[Home feed]
SEARCH[Search]
REL[Related / Up Next]
SUBS[Subscriptions feed]
SHORTS[Shorts]
end
subgraph Reco[Recommendation]
CG([Candidate Gen<br/>two-tower + collaborative])
RANK([Ranker DNN<br/>watch time objective])
RR([Reranker - diversity, safety])
SIG[Signals: watch, like, skip, search]
end
subgraph Engagement
LIKE[Like / dislike]
COMM[Comments]
SUBN[Subscriptions]
NOTIF[Notifications]
PLAY[Playlists]
end
subgraph Ads
ADSVR[Ad server]
AUC[Auction / bidding]
BR[Brand safety]
end
subgraph Live[Live Streaming]
RTMP([Ingest RTMP / SRT])
PKG[Live packager LL-HLS]
DVR[DVR window]
end
subgraph Safety
CP[Content ID]
MOD[Moderation: ML + human]
AGE[Age gating]
end
APP --> PRE --> OBJ
PRE --> QUE
QUE --> SPLIT --> ENC --> PACK --> DRM --> EDGE
ENC --> AUD
SPLIT --> THUMB
SPLIT --> SUB
Viewer --> EDGE
Viewer --> ABR
Viewer --> Discovery
Discovery --> Reco
Reco --> CG --> RANK --> RR --> Viewer
SIG --> Reco
Engagement --> SIG
Ads --- Viewer
Live --> EDGE
Safety --- ENC
Safety --- Discovery
CP --- OBJ
classDef client fill:#dbeafe,stroke:#1e40af,stroke-width:1px,color:#0f172a;
classDef edge fill:#cffafe,stroke:#0e7490,stroke-width:1px,color:#0f172a;
classDef service fill:#fef3c7,stroke:#92400e,stroke-width:1px,color:#0f172a;
classDef datastore fill:#fee2e2,stroke:#991b1b,stroke-width:1px,color:#0f172a;
classDef cache fill:#fed7aa,stroke:#9a3412,stroke-width:1px,color:#0f172a;
classDef queue fill:#ede9fe,stroke:#5b21b6,stroke-width:1px,color:#0f172a;
classDef compute fill:#d1fae5,stroke:#065f46,stroke-width:1px,color:#0f172a;
classDef storage fill:#e5e7eb,stroke:#374151,stroke-width:1px,color:#0f172a;
classDef external fill:#fce7f3,stroke:#9d174d,stroke-width:1px,color:#0f172a;
classDef obs fill:#f3e8ff,stroke:#6b21a8,stroke-width:1px,color:#0f172a;
class APP,ABR client;
class EDGE edge;
class SPLIT,THUMB,PACK,DRM,GGC,HOME,SEARCH,REL,SUBS,SHORTS,SIG,LIKE,COMM,SUBN,NOTIF,PLAY,ADSVR,AUC,BR,PKG,DVR,CP,MOD,AGE service;
class META datastore;
class QUE queue;
class ENC,AUD,SUB,CG,RANK,RR,RTMP compute;
class PRE,OBJ storage;
Transcoding ladders (typical)#
- 144p, 240p, 360p, 480p, 720p, 1080p, 1440p, 2160p (4K), HDR
- Codecs: H.264 (baseline), VP9 (Premium / 4K), AV1 (modern devices).
- Audio: AAC + Opus.
- Output: HLS (Apple) + DASH (rest) segments, typically 2-6 s.
Storage#
- Origin in Colossus (Google) or S3 (other CDNs).
- Many copies per ladder × codec; popular videos pre-pushed to edge.
- Cold videos kept on lower tier.
CDN strategy#
- Google Edge nodes globally.
- Google Global Cache appliances inside large ISPs to save peering cost.
- Anycast routing to nearest POP.
Live streaming#
- Ingest RTMP (legacy) or SRT/WebRTC; transcode on the fly.
- Low-Latency HLS (LL-HLS) for ~2-3 s glass-to-glass.
Content ID#
- Audio + video fingerprint match against rightsholder library.
- Auto-claim → revenue share / block / track.
Glossary & fundamentals#
Concepts referenced in this design. Each row links to its canonical page; the tag column shows whether it is a high-level (HLD) or low-level (LLD) concept.
| Tag | Concept | What it is | Page |
|---|---|---|---|
HLD |
Load balancer / GSLB | L4/L7 traffic distribution and failover | load-balancer |
HLD |
CDN | edge caching for static assets | cdn |
LLD |
REST API design | verbs, statuses, pagination, errors | rest-api-design |
LLD |
Behavioural patterns | Strategy, Observer, State, Command, Chain | behavioral-patterns |
Quick reference#
Functional#
- Resumable video upload.
- Multi-resolution + codec transcode.
- Global delivery via CDN with ABR.
- Discovery: home, search, related, subscriptions, shorts.
- Engagement: likes, comments, subs, notifications, playlists.
- Live streaming + DVR.
- Ads, Premium (ad-free), monetization for creators.
- Content ID copyright management.
Non-functional#
- 2.5B MAU; 500h video / minute uploaded.
- p99 first frame < 2 s globally.
- 99.99% playback availability.
Capacity#
- 500h/min uploads × 60 min × 24h = 720k h/day.
- Avg 1 GB/h raw → 720 PB/day raw → many EB/yr.
- Transcoded ladders push that 3-5× to storage; offset by aggressive cold-tiering.
- View traffic: tens of exabytes/year egress.
Schema highlights#
videos(id, channel_id, title, desc, ts, lang, ladders[], status)engagements(video_id, user_id, type, ts)for watch/likesubs(viewer, channel)embeddings(video_id, vec)
Trade-offs#
- Resumable chunked upload mandatory for large/spotty creator uploads.
- VP9 / AV1 saves egress but costs CPU encoding time; tier roll-out.
- Pre-push vs on-demand to edge: predict by signals; cold videos pull on first miss.
- Watch-time objective pushed dwell up but moderation backlash → balance with safety metrics.
Refs#
- "Deep Neural Networks for YouTube Recommendations" (Covington et al., RecSys '16).
- "Vitess" architecture (YouTube's MySQL scaler).
- Google's CDN / Edge engineering posts; Open Connect (Netflix) for comparison.
- ByteByteGo "Design YouTube", Alex Xu Vol 2.
FAQ#
How does YouTube handle 500 hours of video uploaded per minute?#
Uploads use resumable chunked transfer to origin storage, then a transcoder fleet produces a per title ladder of resolutions and codecs. Work is fanned out across thousands of workers in parallel.
How does YouTube serve video globally with low start time?#
Encoded segments are pushed to a global CDN. Players use adaptive bitrate streaming over HLS or DASH, picking a rung based on bandwidth and buffer to keep p99 playback start under 1.5 seconds.
How does YouTube detect copyrighted content?#
Content ID fingerprints audio and video on upload and matches against a reference database of rights holder assets. Matches trigger block, monetize, or track actions defined by the rights holder.
How does YouTube rank videos in recommendations?#
A two stage system uses candidate generation from collaborative and content embeddings, then a deep ranker scores candidates using watch history, freshness, and dwell time signals.
What storage does YouTube use for video files?#
Originals and transcoded ladders live in Google's distributed object storage. Metadata sits in Spanner-like stores while transient state lives in caches like Memcached and Bigtable.
Further reading#
Curated, high-credibility sources for going deeper on this topic.
- 📄 Paper - Covington et al. - Deep Neural Networks for YouTube Recommendations (RecSys '16)
- 📑 Docs - Vitess - YouTube's MySQL sharding system
- ✍️ Blog - YouTube - Inside the YouTube engineering blog