Design_netflix
Chapter 47: Designing Netflix
Section titled “Chapter 47: Designing Netflix”Building the World’s Largest Video Streaming Platform
Section titled “Building the World’s Largest Video Streaming Platform”47.1 Netflix Overview
Section titled “47.1 Netflix Overview”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 │ └─────────────────────────────────────────────────────────────┘Requirements Analysis
Section titled “Requirements Analysis”| Requirement | Scale | Implication |
|---|---|---|
| Subscribers | 230M+ | Global scale, multi-region |
| Streaming hours | 500M/day | Massive bandwidth needs |
| Content library | 100M+ hours | Large storage, CDN critical |
| Video quality | 4K HDR | High data transfer |
| Availability | 99.99% | Zero tolerance for downtime |
| Latency | < 5 seconds start | Optimized delivery |
47.2 High-Level Architecture
Section titled “47.2 High-Level Architecture” 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) │ │ │ │ │ └──────────┘ └──────────┘ │ └─────────────────────────────────────────────────────────────┘47.3 Key Components Deep Dive
Section titled “47.3 Key Components Deep Dive”47.3.1 Open Connect CDN
Section titled “47.3.1 Open Connect CDN”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 directlyVideo Encoding & Adaptive Streaming
Section titled “Video Encoding & Adaptive Streaming” 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 │ └─────────────────────────────────────────────────────────────┘47.3.2 Microservices Architecture
Section titled “47.3.2 Microservices Architecture” 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 │ └─────────────────────────────────────────────────────────────┘47.3.3 Database Strategy
Section titled “47.3.3 Database Strategy” 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 │ │ │ └─────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────┘47.4 Resilience Patterns
Section titled “47.4 Resilience Patterns”Chaos Engineering
Section titled “Chaos Engineering”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 │ └─────────────────────────────────────────────────────────────┘Circuit Breaker Pattern
Section titled “Circuit Breaker Pattern”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 └──────────────────────────47.5 Key Learnings from Netflix
Section titled “47.5 Key Learnings from Netflix”What Made Netflix Successful
Section titled “What Made Netflix Successful” 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-mileSummary
Section titled “Summary”- Open Connect CDN - Custom CDN for video delivery
- 1000+ microservices - Independent, scalable services
- Cassandra - Primary NoSQL database at scale
- Chaos Engineering - Test failures with Simian Army
- Hystrix - Circuit breaker pattern
- Adaptive streaming - Quality based on bandwidth
- Data-driven - Recommendations, A/B testing