Skip to main content

Design Netflix

Design and Implement a Video Streaming App.

Netflix is a popular video streaming service that allows users to watch a wide variety of award-winning TV shows, movies, documentaries, and more on thousands of internet-connected devices.

Examples: Netflix, Amazon Prime Video, Hulu, Disney+, HBO Max.

Requirements

Functional Requirements

  • Watch movies and TV shows
  • Search by genre, name, actor
  • Multiple user profiles with personalized recommendations
  • Offline downloads for watching content without an internet connection
  • Support multiple devices like Smart TVs, smartphones, tablets, and desktops
  • Support multiple languages and subtitles
  • Support parental controls for restricting content based on age
  • Support user reviews, ratings, and recommendations
  • Support search and filtering options for finding content easily
  • Support notifications for new content, recommendations, and updates

Non-Functional Requirements

  • Support wide range of devices: mobile, tablet, desktop, Smart TV
  • Adaptive bitrate streaming for different network conditions
  • Ensure accessibility (screen readers, keyboard navigation)
  • Minimize battery consumption, memory usage, and CPU resource consumption

High-Level Design

Let's draw a high level diagram including the Server part. It's important to to see the big picture and have an understanding how these building blocks work with each other even if you are a Frontend Developer.

The High Level Design of Netflix should include the following blocks:

Core Architectural Components

  • Clients: Applications for web, mobile, and TV platforms.
  • Communication Layer:
    • WebSocket for persistent real-time connections.
    • REST API Gateway for standard HTTP interactions.
  • Services:
    • Auth Service: Handles user authentication and authorization.
    • Content Service: Manages movies, TV shows, and other content.
    • User Service: Manages user profiles, recommendations, and preferences.
    • Notification Service: Sends push notifications to clients.
  • Data Storage:
    • User, Content, and Media databases.
    • Cache layers for improved performance.
    • Message queues for asynchronous processing (e.g., Kafka).

Technologies

  • Database: Use Cassandra for scalability and Redis for caching.
  • Media Storage: Blob storage for videos, backed by a CDN.
  • Queue Systems: Kafka for handling events and message processing.
  • Load Balancers: Ensure equal traffic distribution.

Low Level Design

Video Quality Types

Netflix supports a range of video quality options to cater to varying bandwidths and devices:

  • Standard Definition (SD): 480p, providing a basic viewing experience while conserving bandwidth.
  • High Definition (HD): 720p and 1080p, offering clearer visuals.
  • Ultra HD/4K: 2160p, delivering premium quality but requiring higher bandwidth.
  • High Dynamic Range (HDR): Enhances color accuracy and contrast for a more immersive viewing experience.

Streaming Types

There are multiple streaming techniques to optimize playback:

  • Progressive Streaming: Downloads video in chunks, suitable for stable connections.
  • Adaptive Bitrate Streaming (ABR): Dynamically adjusts video quality based on bandwidth.
    • ABR Protocols: HLS, MPEG-DASH, HDS, and Smooth Streaming facilitate seamless quality transitions.

Subtitles are supported in formats like SRT and VTT, with customizable font, color, and size. Common video formats include MP4 for cross-browser compatibility, WebM for modern browsers, and Ogg as an open-source alternative.

User Authentication

  • Description: Users need to sign up and log in to access the content.

  • Components:

    • Auth Service: Handles user authentication and authorization.
    • Database: Stores user credentials and session tokens.
    • Client: Web, mobile, and TV applications for user interaction.
  • Flow:

    1. User signs up with email and password.
    2. Auth Service validates the credentials and generates a session token.
    3. User logs in with the session token.
    4. Client stores the session token for future requests.

Content Management

  • Description: Users can browse, search, and watch movies, TV shows, and documentaries.

  • Components:

    • Content Service: Manages movies, TV shows, and other content.
    • Database: Stores content metadata, ratings, and reviews.
    • Client: Web, mobile, and TV applications for content discovery.
  • Flow:

    1. User browses the catalog of movies, TV shows, and documentaries.
    2. Content Service fetches content metadata from the database.
    3. User searches for specific content using filters and keywords.
    4. Content Service returns search results based on user preferences.

API Endpoints

GET /api/v1/movies
GET /api/v1/movies/:id
GET /api/v1/search?q=:query


POST /api/v1/reviews
GET /api/v1/reviews/:id
POST /api/v1/ratings
GET /api/v1/ratings/:id
POST /api/v1/recommendations
GET /api/v1/recommendations/:id
POST /api/v1/notifications
GET /api/v1/notifications/:id

Data Model Schema

  • Movie
type Movie {
id: number;
title: string;
genre: string[];
duration: number;
rating: number;
episodes: Episode[];
}
  • User
type User {
id: number;
name: string;
photo_url: string;
movies: []
}

Security

Protecting video content is a priority. There are several different ways to protect content:

  • Digital Rights Management (DRM): Prevents unauthorized access.
  • Encrypted Media Extensions (EME): Ensures secure playback of premium content.

Performance

  • Network
    • Data compression. Use Brotli for text formats such as HTML, CSS, JS and GZIP for binary files
  • Images
    • Use lazy-loading
    • Use modern images formats: webp, png
  • Video
  • CSS
  • Javascript