Skip to content

Design_netflix

Building the World’s Largest Video Streaming Platform

Section titled “Building the World’s Largest Video Streaming Platform”

Netflix is the world’s leading streaming entertainment service with over 230 million subscribers in more than 190 countries.

Netflix by the Numbers
====================
┌─────────────────────────────────────────────────────────────┐
│ 230M+ subscribers │
│ 190+ countries │
│ 500M+ hours watched daily │
│ 100M+ hours of content │
│ ~50% of US internet bandwidth at peak │
└─────────────────────────────────────────────────────────────┘
RequirementScaleImplication
Subscribers230M+Global scale, multi-region
Streaming hours500M/dayMassive bandwidth needs
Content library100M+ hoursLarge storage, CDN critical
Video quality4K HDRHigh data transfer
Availability99.99%Zero tolerance for downtime
Latency< 5 seconds startOptimized delivery

Netflix Architecture Overview
===========================
┌─────────────────────────────────────────────────────────────┐
│ Users │
│ (Mobile, TV, Web, Tablet) │
└────────────────────────────┬────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Open Connect CDN │
│ (Servers in ISP networks globally) │
│ │
│ Delivers 100% of video traffic! │
└────────────────────────────┬────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Zuul Gateway │
│ (API Gateway, Edge Services) │
└────────────────────────────┬────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Netflix OSS Services │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │ Eureka │ │ Hystrix │ │Ribbon │ │ Feign │ │
│ │Service │ │ Circuit │ │ Load │ │ HTTP │ │
│ │Registry │ │ Breaker │ │Balancer │ │Client │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
└────────────────────────────┬────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Microservices │
│ │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │ Playback│ │ Content │ │ User │ │Billing │ │
│ │ Service │ │ Service │ │ Service │ │ Service │ │
│ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │
│ │
│ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │
│ │Search │ │Rating │ │Profile │ │History │ │
│ │ Service │ │ Service │ │ Service │ │ Service │ │
│ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │
└────────────────────────────┬────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Data Layer │
│ │
│ ┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐ │
│ │Cassandra │ │ MySQL │ │S3/Blob │ │Elastic │ │
│ │(NoSQL) │ │(Relational)│ │Storage │ │search │ │
│ └──────────┘ └──────────┘ └──────────┘ └──────────┘ │
│ │
│ ┌──────────┐ ┌──────────┐ │
│ │ EVCache │ │ Elasticsearch│ │
│ │(Redis) │ │ │ │
│ └──────────┘ └──────────┘ │
└─────────────────────────────────────────────────────────────┘

Netflix built its own CDN optimized for video delivery.

Open Connect Architecture
=======================
┌─────────────────────────────────────────────────────────────┐
│ Netflix Data Centers │
│ (Origin servers, upload content here) │
└────────────────────────────┬────────────────────────────────┘
│ Content upload
┌─────────────────────────────────────────────────────────────┐
│ ISP Point of Presence │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Open Connect Appliance (OCA) │ │
│ │ │ │
│ │ • Server in ISP network │ │
│ │ • Stores popular content locally │ │
│ │ • Delivers video directly to users │ │
│ │ • 100TB+ storage each │ │
│ │ • 100Gbps network │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Open Connect Appliance (OCA) │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
└────────────────────────────┬────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ User │
│ (Plays video!) │
└─────────────────────────────────────────────────────────────┘
Why build your own CDN?
───────────────────────
• 50% of US internet traffic at peak
• Better economics (no CDN middleman)
• Optimized for video streaming
• Partner with ISPs directly
Video Processing Pipeline
=======================
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Master │────▶│ Transcode │────▶│ Storage │
│ Video │ │ (150+) │ │ (S3) │
└─────────────┘ └─────────────┘ └─────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Multiple Quality Profiles Created: │
│ │
│ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐ ┌──────┐│
│ │4K HDR│ │1080p │ │ 720p │ │ 480p │ │ 360p │ │ 240p ││
│ │35Mbps│ │5Mbps │ │2.5Mps│ │1Mbps │ │0.5Mps│ │0.3Mps││
│ └──────┘ └──────┘ └──────┘ └──────┘ └──────┘ └──────┘│
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Adaptive Bitrate Streaming (HLS/DASH) │
│ │
│ Client requests: Chunk list → Downloads video chunks │
│ Based on bandwidth: Switches quality automatically │
└─────────────────────────────────────────────────────────────┘
Netflix Microservices
===================
1000+ microservices in production!
┌─────────────────────────────────────────────────────────────┐
│ Content Pipeline │
│ ─────────────────────────────────────────────────────────│
│ • Content Metadata Service │
│ • Transcoding Workflow Service │
│ • Asset Management Service │
│ • Availability Service │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Playback │
│ ─────────────────────────────────────────────────────────│
│ • Playback API Service │
│ • Quality Selection Service │
│ • Video Playback Service │
│ • Player Configuration Service │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Discovery │
│ ─────────────────────────────────────────────────────────│
│ • Recommendation Service │
│ • Personalized Ranking Service │
│ • Trending Now Service │
│ • Because You Watched Service │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ User Management │
│ ─────────────────────────────────────────────────────────│
│ • User Identity Service │
│ • Profile Service │
│ • Preferences Service │
│ • Household Service │
└─────────────────────────────────────────────────────────────┘
Netflix Data Architecture
=======================
┌─────────────────────────────────────────────────────────────┐
│ Primary Data Stores │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Apache Cassandra │ │
│ │ │ │
│ │ • User accounts │ │
│ │ • Play history │ │
│ │ • Ratings │ │
│ │ • 2,500+ nodes │ │
│ │ • 100TB+ data │ │
│ │ • 1M+ writes/sec │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ MySQL (Aurora) │ │
│ │ │ │
│ │ • Billing & subscriptions │ │
│ │ • Partner integrations │ │
│ │ • ACID transactions needed │ │
│ └─────────────────────────────────────────────────────┘ │
│ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Elasticsearch │ │
│ │ │ │
│ │ • Search │ │
│ │ • Content metadata │ │
│ │ • Full-text search │ │
│ └─────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘

Netflix pioneered chaos engineering to build resilient systems.

The Simian Army
==============
Netflix built tools to inject failures:
┌─────────────────────────────────────────────────────────────┐
│ Chaos Monkey │
│ ─────────────────────────────────────────────────────────│
│ • Randomly terminates instances │
│ • Tests auto-scaling │
│ • Runs during business hours │
│ • Can be whitelisted │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Chaos Gorilla │
│ ─────────────────────────────────────────────────────────│
│ • Simulates entire AZ failure │
│ • Tests multi-AZ architecture │
│ • Verifies failover works │
└─────────────────────────────────────────────────────────────┘
┌─────────────────────────────────────────────────────────────┐
│ Chaos Kong │
│ ─────────────────────────────────────────────────────────│
│ • Simulates entire region failure │
│ • Tests disaster recovery │
│ • Most extreme test │
└─────────────────────────────────────────────────────────────┘

Netflix developed Hystrix, the circuit breaker library.

Hystrix in Action
=================
Without Hystrix: With Hystrix:
─────────────── ───────────────
Request ──▶ Service A Request ──▶ Hystrix
│ │
▼ ▼
Service B Check Circuit
│ │
▼ ├─▶ CLOSED ──▶ Service B
(slow/fail) │ │
│ │ │ (failure threshold)
▼ │ ▼
Requests pile up │ OPEN ──▶ Return Fallback
│ │ │
▼ │ ▼
System crash! │ HALF-OPEN ──▶ Test
└──────────────────────────

Netflix Engineering Principles
============================
1. BUILD, NOT BUY
───────────────
• Open Connect CDN (custom built)
• Cassandra (heavily modified)
• Many open-source tools released
2. CHAOS ENGINEERING
──────────────────
• Test failure regularly
• Automate recovery
• Don't hope for reliability, test it
3. MICROSERVICES
───────────────
• 1000+ independent services
• Teams own their services end-to-end
• API-first design
4. DATA-DRIVEN
────────────
• A/B testing everything
• Recommendation algorithms
• Personalization at scale
5. EDGE FIRST
───────────
• CDN at the edge
• Minimize origin traffic
• Optimize for last-mile

  1. Open Connect CDN - Custom CDN for video delivery
  2. 1000+ microservices - Independent, scalable services
  3. Cassandra - Primary NoSQL database at scale
  4. Chaos Engineering - Test failures with Simian Army
  5. Hystrix - Circuit breaker pattern
  6. Adaptive streaming - Quality based on bandwidth
  7. Data-driven - Recommendations, A/B testing

Next: Chapter 48: Designing Uber