Design Netflix: System Design Interview Guide
Master how to design Netflix-like video streaming service.
20+ years shipping production code across the stack, with years spent interviewing engineers. Notes here come from systems that actually shipped.
- ✓Basic understanding of distributed systems
- ✓Familiarity with CDN, load balancers, and caching
- ✓Knowledge of SQL and NoSQL databases
- ✓Understanding of microservices architecture
- Understand requirements: functional (user management, video streaming, search, recommendations) and non-functional (high availability, low latency, scalability).
- Design a CDN for video delivery, use adaptive bitrate streaming.
- Use microservices for user profiles, video metadata, recommendations, etc.
- Store metadata in SQL (sharded) and user activity in NoSQL.
- Use caching (CDN, Redis) and async processing for encoding and recommendations.
Think of Netflix as a giant library where millions of people want to borrow movies at the same time. You need a smart librarian (recommendation system) to suggest movies, a fast delivery system (CDN) to get the movie to each person quickly, and a way to keep track of who has what (database). The system must work even if some parts break, and handle sudden rushes like new releases.
Designing Netflix is a classic system design interview question that tests your ability to architect a large-scale, distributed, and highly available video streaming service. Netflix serves over 200 million subscribers, streaming billions of hours of content monthly. The system must handle massive concurrent users, provide low-latency video playback, and offer personalized recommendations. In this guide, we'll walk through a structured approach to design Netflix, covering requirements, high-level architecture, data models, key components like CDN and adaptive bitrate streaming, and scaling strategies. We'll also discuss common pitfalls and how to ace the interview by communicating your thought process clearly. By the end, you'll be ready to tackle this question with confidence.
1. Requirements Gathering
Start by clarifying functional and non-functional requirements. Functional: user registration/login, browse/search movies, stream video, rate content, get recommendations. Non-functional: high availability (99.99% uptime), low latency (<200ms for metadata, <2s for video start), scalability to millions of concurrent users, durability of user data, and cost efficiency. Also consider geo-distribution for global audience.
2. High-Level Architecture
Design a layered architecture: Client (apps on various devices) -> CDN (for video) -> Load Balancer -> API Gateway -> Microservices (User, Video Metadata, Recommendation, Encoding, etc.) -> Databases (SQL for metadata, NoSQL for user activity) -> Cache (Redis) -> Message Queue (Kafka) for async tasks. Video files are stored in a distributed file system (like S3) and served via CDN. Use adaptive bitrate streaming (HLS or DASH) to adjust quality based on network.
3. Data Models
Design schemas for key entities. User: userId (PK), name, email, subscription plan, etc. Video: videoId (PK), title, description, duration, genre, release year, etc. WatchHistory: userId, videoId, timestamp, progress. Ratings: userId, videoId, rating. Use SQL for transactional data (users, videos) with sharding by userId or videoId. Use NoSQL (Cassandra) for high-write user activity (watch history, ratings) with partition key userId and clustering key timestamp.
4. Video Streaming and CDN
Video files are large (GBs). Store original videos in S3 and encode into multiple bitrates (240p, 480p, 720p, 1080p, 4K). Use adaptive bitrate streaming: client requests manifest file listing available bitrates, then fetches segments (2-10s chunks) from CDN. CDN caches popular content at edge servers. For less popular content, CDN fetches from origin. Use DNS-based routing to direct user to nearest edge. Implement pre-fetching for next likely video based on recommendations.
5. Recommendation System
Recommendations are crucial for user engagement. Use a hybrid approach: collaborative filtering (users with similar tastes) and content-based filtering (similar genres, actors). Offline batch processing (Spark) generates recommendations periodically. Online real-time component uses recent user activity to adjust. Store precomputed recommendations in a key-value store (Redis) keyed by userId. For new users, use popularity-based recommendations.
6. Scaling and Fault Tolerance
Scale horizontally: add more microservice instances, shard databases, add CDN nodes. Use load balancers (ELB) to distribute traffic. For fault tolerance, implement circuit breakers (Hystrix), retries with exponential backoff, and bulkheads. Use health checks and auto-scaling groups. For data durability, replicate across AZs and regions. Use leader election for critical services (e.g., encoding job scheduler).
7. Search and Browse
Implement search using Elasticsearch for full-text search on video titles, descriptions, and actors. Index videos and update as new content added. For browse, use a combination of precomputed lists (e.g., 'Trending Now', 'New Releases') stored in Redis. Use pagination with cursor-based to avoid offset issues. For autocomplete, use a trie or Elasticsearch's completion suggester.
8. Monitoring and Analytics
Collect metrics: CDN latency, video start time, buffering ratio, error rates, database query latency. Use a time-series database (InfluxDB) and visualization (Grafana). Set up alerts for anomalies. For analytics, stream user events (play, pause, search) to Kafka, then process with Spark Streaming for real-time dashboards and batch for business intelligence.
Netflix CDN Outage on Christmas Eve 2012
- Always have automated failover and load testing for peak traffic.
- Monitor CDN health and have manual override capabilities.
- Use multiple CDN providers to avoid single point of failure.
- Implement gradual rollouts for configuration changes.
- Conduct chaos engineering exercises regularly.
curl -o /dev/null -s -w '%{time_starttransfer}' https://cdn.netflix.com/video.mp4dig +short cdn.netflix.com| File | Command / Code | Purpose |
|---|---|---|
| architecture_overview.txt | Client (TV, Mobile, Web) | 2. High-Level Architecture |
| schema.sql | CREATE TABLE users ( | 3. Data Models |
| manifest.m3u8 | low.m3u8 | 4. Video Streaming and CDN |
| recommendation_pipeline.py | from pyspark.ml.recommendation import ALS | 5. Recommendation System |
| search_index.py | from elasticsearch import Elasticsearch | 7. Search and Browse |
Key takeaways
Common mistakes to avoid
4 patternsIgnoring non-functional requirements like latency and availability.
Designing a monolithic architecture.
Not considering CDN for video delivery.
Overlooking data partitioning and replication.
Interview Questions on This Topic
Design a video streaming service like Netflix. Focus on the video upload and encoding pipeline.
Frequently Asked Questions
20+ years shipping production code across the stack, with years spent interviewing engineers. Notes here come from systems that actually shipped.
That's System Design Interview. Mark it forged?
3 min read · try the examples if you haven't