Design YouTube: video upload, transcoding, and CDN
Youtube
Guided ModeStreaming Service: Adaptive Bitrate Playback
The Streaming Service returns the HLS manifest URL. The client player fetches 6-second segments directly from the segment store via that URL, and an ABR algorithm continuously selects the best quality for the current bandwidth.
Request Flow
Fetch manifest
Viewer requests /watch/:id. The API calls the Streaming Service which fetches the manifest URL from the Metadata Service and returns it.
// Response
{
manifest: 'https://storage.../master.m3u8',
thumbnail: 'https://cdn.../thumb.jpg',
duration: 3600
}Client parses manifest
The player downloads master.m3u8, which lists available qualities: 4K (14 Mbps), 1080p (4.5 Mbps), 720p (2.2 Mbps), 480p (0.85 Mbps), 144p (0.09 Mbps). It picks the starting quality based on initial bandwidth estimate.
#EXTM3U #EXT-X-STREAM-INF:BANDWIDTH=14000000,RESOLUTION=3840x2160 4k/index.m3u8 #EXT-X-STREAM-INF:BANDWIDTH=4500000,RESOLUTION=1920x1080 1080p/index.m3u8
ABR switches quality
Every 6 seconds (one segment), the ABR algorithm measures download speed. If bandwidth drops, it picks a lower resolution for the next segment β transition is seamless, no buffering.
// ABR loop downloadSpeed = measure(lastSegment) nextQuality = selectBestQuality(downloadSpeed, bufferHealth) nextSegment = fetch(nextQuality, segmentIndex++)
Why We Need This
Fixed-quality streaming fails on variable networks. ABR was invented because a video that plays perfectly at home over 50 Mbps must degrade gracefully to 360p on a train. Without ABR, you'd choose between quality and reliability.
Key Insight
ABR is a real-time control loop running in the client player. The server's job is to produce and serve all quality variants β the client decides which to play based on current conditions. This is why YouTube works on 2G.
Step 7 of 9
