Covers building highly-resilient file upload paths, video transcoding pipelines, CDN caching edge servers, and adaptive streaming protocols.
A video streaming service like YouTube or Netflix splits the system into two distinct workflows:
When a raw video is uploaded, it is massive (e.g. 10GB raw 4K recording). We cannot stream this raw file directly to mobile users on 4G networks. We must transcode it.
We build a **Directed Acyclic Graph (DAG)** pipeline to run processing tasks in parallel:
.m3u8).We do not download the entire video file at once. Instead, we stream small, sequential chunks (typically 2-10 seconds long). Two popular streaming protocols are **HLS** (HTTP Live Streaming, built by Apple) and **DASH** (Dynamic Adaptive Streaming over HTTP).
Adaptive streaming ensures the player switches video quality dynamically based on the user's current internet connection.
• The transcoder generates multiple streams (e.g., 240p, 480p, 1080p) along with an index Manifest file listing the URLs for all chunks.
• The player downloads the manifest file first. It constantly measures network speed.
• If network speed drops, the player downloads the next 5-second chunk from the 360p pool. If speed increases, it requests the 1080p pool chunk.
Videos are highly bandwidth-intensive. We must use a Content Delivery Network (CDN) to serve video files from edge caches located close to users. However, caching all videos at the edge is too expensive. We cache **hot videos** (new uploads and viral videos) on CDNs, while **cold videos** are fetched directly from our origin Object Store nodes.