AlgoViz

Design Netflix

hard 45 min

Paying members press play and a film starts within two seconds, in the quality they paid for.

Video lesson · Chapter 1 of 5

Press Play while a million other viewers press it too

0:00 / 4:33

Filled the night before, in 90 seconds

1:30Reel coming soon

Theory

Read or listen first. About 2 min.

What it is

A subscription streaming service lends a chosen library of films and series to paying members on any screen. Each play is a question (may this account watch this title here, now?) followed by a long stream of bytes.

The question is answered by the control plane: accounts, plans, licences, positions, home pages. The bytes come from the data plane: boxes with disks, close to the viewers, that know nothing about people.

Why it exists

The bytes are enormous: we assume 29 million streams at the same time, 144 Tb/s. The questions are small: about a million requests a second, mostly heartbeats. Different loads deserve different systems.

The library is small: 17,000 titles are about 2 PB in all qualities. That fits on 18 machines of the size we assume, so a place can hold everything, or the part that people will want tomorrow. A public upload site cannot do that.

A short history

  1. August 2008 to January 2016

    By its own account, Netflix starts to move to the cloud after a database corruption in 2008 and shuts down the last streaming data center parts in early January 2016.

  2. 2011

    Netflix begins Open Connect, its own delivery network with caches that are filled ahead of demand, says its overview paper.

  3. August 2014

    A SIGCOMM paper shows a player that chooses quality from its buffer, tested with users of a commercial service.

  4. September 2017

    Encrypted Media Extensions become a W3C Recommendation: a web page can ask the browser's licence system to play protected video.

Words to know

Control plane
Services that decide: who, what, from where.
Data plane
Machines that send the bytes.
Edge box
Our cache server in a provider's network or at an exchange.
Fill
Copying files to boxes before anyone asks.
Steering
Choosing which boxes a device should use.
DRM
Digital rights management: files are encrypted, and a licence carries the key and its rules.
Ladder
The qualities of a title, from lowest to highest.
VMAF
A score from 0 to 100 for how good a picture looks, developed by Netflix and open source.
Lease
A right that ends by itself unless it is renewed.

Solve it like an interview

New to it? Start with Approach. Revising? Go straight to the mock.

  1. 1ApproachWhat this question tests, where it gets hard, and how to spend the time.
  2. 2ScopeAsk what changes the design, then commit to a short list.
  3. 3NumbersWork out a number when the answer changes what you build.
  4. 4API and dataThe contract first, then the data that serves it.
  5. 5DesignStart with the smallest system that works. Change it only when something breaks.
  6. 6Deep divesCompare the options before you open them, then say which you would pick.
  7. 7Explain your choicesAnswer first. Then compare your reasoning.
  8. 8By levelThe same question is judged differently for mid, senior and staff.
  9. 9MockAnswer against the clock, then score yourself.

Understand it

Picture it

Film tins on village shelves

Put there the night before
FILMSA long road, an empty shelf

Plan by day, carry by night, open with a key, and know the next shelf.

Scope

What are we building?

A service like Netflix: browse, play, continue later, download. Numbers are our assumptions. Where we say what Netflix does, the sentence comes from its own pages, listed under sources.

  • Encode once

    A ladder for each title, since a cartoon needs fewer bits than a battle.

  • Fill early

    Known library, predicted demand, quiet nights.

  • Decide quickly

    Plan, country, age, streams, licence: in one call.

  • Keep playing

    Next box, lower quality, another region.

Similar services

ServiceWhat differs
Disney+, Max, Hulu, Peacock, Paramount+Same problem, other libraries
Amazon Prime VideoPart of a shop, also live sport
Apple TV+Small library of its own
YouTubeAnyone uploads; most videos are cold
SpotifySmall files, songs in a row

The finished system

Where the design ends up

The whole system

Devices talk to the control plane through a gateway: playback, licence, home and search services with MySQL, Cassandra and a cache. Video segments come from edge boxes at internet providers, then exchange boxes. A fill planner copies files from object storage at night. Encoders turn masters into encrypted files.
Blue decides, orange carries video, dashed happens ahead or in the background.

Read next

Who owns which idea

IdeaIts own page
Uploads, splitting, parallel encodingYouTube
Tiers, push and pullCDN design
A CDN for many customersContent delivery network
Candidates and rankingRecommendation system
Breakers, fallbacks, timeoutsCircuit breaker, Fallbacks, Timeouts
Several regionsHigh availability stacks
Tables for each questionNoSQL
Changes as a streamChange data capture
Old devicesAPI versioning
Many requests at one momentThundering herd

For the interview: Approach, then Scope, Numbers, API and data, Design and Deep dives. For revision, go to the Mock.

Summary

The whole topic in one minute.

Encode each title once and carefully, then place the files near viewers at night by predicted demand. In the evening the control plane checks the account, gives a licence, and returns a list of boxes. The player fetches segments, chooses quality from its buffer, and moves to the next box if one fails.

Everything around that is small data with clear rules: a lease for each running stream, positions that are saved now and then, home pages that are computed ahead, and several regions that can each take over.

  • 144 Tb/s of bytes and one million small requests a second are two systems.
  • 2 PB fits in one exchange site, so origin reads are rare.
  • Place by views for each gigabyte, at night.
  • The buffer is the safety net: fill it first, then raise quality.
  • A stream is a lease. Nobody has to press stop.
  • Running films survive a control plane failure; new plays need another region.

Sources