View Categories

Netflix Architecture – Adaptive Bitrate Streaming

4 min read

The “Single File” Misconception #

When you upload a video to a standard web server (like an MP4 file in an HTML5 <video> tag), you are forcing the user to download that specific file.

  • If the file is 4K and the user is on a subway with 3G signal, the video buffers endlessly.
  • If the file is 480p and the user is on Fiber internet on a 60-inch TV, it looks pixelated.

The Logic Check: You cannot serve a “One Size Fits All” file. Netflix does not stream “a movie.” It streams thousands of tiny, separate files. When you press play, you aren’t downloading movie.mp4. You are downloading chunk_1_1080p.ts, then chunk_2_720p.ts (if your network drops), then chunk_3_1080p.ts (if it recovers).

The Core Logic: Adaptive Bitrate (ABR) #

The intelligence of Netflix is not in the Server; it is in the Client Player. This approach is called DASH (Dynamic Adaptive Streaming over HTTP) or HLS (Apple’s HTTP Live Streaming).

1. The Ladder (Encoding) Before a movie goes live, Netflix takes the raw master file (Terabytes size) and runs it through a massive transcoding pipeline on AWS. They generate a “Ladder” of files:

  • Bitrate 250kbps: Resolution 240p (For bad networks).
  • Bitrate 3000kbps: Resolution 720p.
  • Bitrate 16000kbps: Resolution 4K.

2. The Manifest (.m3u8 / .mpd) The client downloads a “Menu” file (Manifest). This tells the player: “Here are the URL options for every 4-second chunk of video.”

3. The Client Logic The Netflix player on your TV constantly monitors your bandwidth.

  • Algorithm: “I downloaded the last 4 seconds in 0.5 seconds. My speed is high. Request the next chunk in 4K.”
  • Network Drop: “The last chunk took 3.5 seconds. Danger! Request the next chunk in 720p to avoid buffering.”

Architecture Diagram: The Transcoding Pipeline #

Netflix uses AWS for the “Brains” (Encoding/Logic) but their own hardware for the “Body” (Delivery).

graph TD
    Source["Raw Master File"] --> AWS["AWS Cloud (The Brains)"]
    
    subgraph Pipeline ["Encoding Pipeline (Parallel)"]
        AWS --> Enc1["Encoder: 240p"]
        AWS --> Enc2["Encoder: 1080p"]
        AWS --> Enc3["Encoder: 4K"]
    end
    
    Enc1 -- "Split into 4s Chunks" --> Chunks1["Small Files"]
    Enc2 -- "Split into 4s Chunks" --> Chunks2["Small Files"]
    Enc3 -- "Split into 4s Chunks" --> Chunks3["Small Files"]
    
    Chunks1 --> CDN["Open Connect (The Body)"]
    Chunks2 --> CDN
    Chunks3 --> CDN
    
    CDN -- "Serves Chunks" --> User["User Device"]
    
    %% The Adaptive Bitrate Feedback Loop
    User -.-> |"Selects Quality <br/> (Based on Bandwidth)"| CDN

The “Open Connect” Logic (Custom CDN) #

Most companies use Akamai or Cloudflare. Netflix built their own CDN called Open Connect. Why? The sheer volume. Netflix consumes ~15% of the entire global internet bandwidth. Paying Akamai fees would bankrupt them.

The Architecture:

  • OCAs (Open Connect Appliances): These are physical boxes (hard drives) that Netflix gives to ISPs (like Comcast, Verizon, Airtel) for free.
  • The Logic: They ask the ISP: “Please plug this box into your data center.”
  • The Result: When you stream Stranger Things, the video data doesn’t travel across the Atlantic Ocean cable. It travels from a red box sitting inside your local ISP’s building, 5 miles from your house.
  • Latency: Near zero.
  • Cost: The ISP saves money (less traffic on their backbone), and Netflix saves money (no transit fees).

The Decision Matrix: Live vs. VOD #

Streaming logic changes entirely if the video is Live (Twitch/Sports) vs. On-Demand (Netflix).

FeatureVOD (Netflix/YouTube)Live (Twitch/Zoom)
EncodingPre-Computed. Spend hours encoding the perfect 4K file. High CPU cost once.Real-Time. Must encode now. Compromise quality for speed.
BufferingAggressive. Download 2 minutes ahead if possible.Minimal. You can’t buffer the future.
ProtocolTCP (HTTP). Reliability is king. If a packet drops, re-send it. We want quality.UDP / WebRTC. Latency is king. If a packet drops, skip it. Don’t pause the meeting.
LatencyIrrelevant. (Who cares if the movie “starts” 2 seconds slower?)Critical. (You can’t have a conversation with 5s delay).

Real-World Case Study: “The Crown” Header Injection #

Netflix adds “Header Injection” into their files for testing. Sometimes, they intentionally break a specific chunk (e.g., make chunk #50 corrupt) for 1% of users.

  • Why? To test if their Player Client handles the error gracefully (e.g., by skipping to chunk #51 or downgrading quality) without crashing.
  • The Logic: The system is so complex that “Chaos Engineering” is the only way to ensure reliability.

Conclusion #

Video streaming is an illusion. It is just a very fast file transfer of very small files.

  • Don’t build a video server; build a File Server.
  • Don’t manage quality on the server; let the Client decide.
  • Move the data physically closer to the user (CDN) because you cannot beat the speed of light.