Techniques for Scaling the Netflix API - QCon SF

98
Techniques for Scaling the Netflix API By Daniel Jacobson @daniel_jacobson [email protected] QCon SF 2011

description

This presentation was from QCon SF 2011. In these slides I discuss various techniques that we use to scale the API. I also discuss in more detail our effort around redesigning the API.

Transcript of Techniques for Scaling the Netflix API - QCon SF

Page 1: Techniques for Scaling the Netflix API - QCon SF

Techniques for Scaling the Netflix API

By Daniel Jacobson@daniel_jacobson

[email protected]

QCon SF 2011

Page 2: Techniques for Scaling the Netflix API - QCon SF

Techniques for Scaling the Netflix API

Agenda

• History of the Netflix API• The Cloud• Development and Testing• Resiliency• Future of the Netflix API

Page 3: Techniques for Scaling the Netflix API - QCon SF

Techniques for Scaling the Netflix API

Agenda

• History of the Netflix API• The Cloud• Development and Testing• Resiliency• Future of the Netflix API

Page 4: Techniques for Scaling the Netflix API - QCon SF

Netflix API

Page 5: Techniques for Scaling the Netflix API - QCon SF

Netflix API Requests by AudienceAt Launch In 2008

Netflix DevicesOpen API Developers

Page 6: Techniques for Scaling the Netflix API - QCon SF
Page 7: Techniques for Scaling the Netflix API - QCon SF
Page 8: Techniques for Scaling the Netflix API - QCon SF

Netflix API

Page 9: Techniques for Scaling the Netflix API - QCon SF

Netflix Devices Open API Developers

Netflix API Requests by AudienceAt Launch Today

Page 10: Techniques for Scaling the Netflix API - QCon SF

Public API

Private API

Page 11: Techniques for Scaling the Netflix API - QCon SF

Current Emphasis of Netflix API

Netflix Devices

Page 12: Techniques for Scaling the Netflix API - QCon SF

Techniques for Scaling the Netflix API

Agenda

• History of the Netflix API• The Cloud• Development and Testing• Resiliency• Future of the Netflix API

Page 13: Techniques for Scaling the Netflix API - QCon SF
Page 14: Techniques for Scaling the Netflix API - QCon SF

Discovery

Page 15: Techniques for Scaling the Netflix API - QCon SF

Discovery

Page 16: Techniques for Scaling the Netflix API - QCon SF

Streaming

Page 17: Techniques for Scaling the Netflix API - QCon SF

Netflix API Powers Discovery

Page 18: Techniques for Scaling the Netflix API - QCon SF

Netflix API : Requests Per Month

Jan-10 Feb-10 Mar-10 Apr-10 May-10 Jun-10 Jul-10 Aug-10 Sep-10 Oct-10 Nov-10 Dec-10 Jan-11 Feb-11 Mar-11 Apr-11 May-11 Jun-11 Jul-11 -

5

10

15

20

25

30

35

Requ

ests

in B

illio

ns

Page 19: Techniques for Scaling the Netflix API - QCon SF

Netflix API : Requests Per Month

Jan-10 Feb-10 Mar-10 Apr-10 May-10 Jun-10 Jul-10 Aug-10 Sep-10 Oct-10 Nov-10 Dec-10 Jan-11 Feb-11 Mar-11 Apr-11 May-11 Jun-11 Jul-11 -

5

10

15

20

25

30

35

Requ

ests

in B

illio

ns

Page 20: Techniques for Scaling the Netflix API - QCon SF
Page 21: Techniques for Scaling the Netflix API - QCon SF
Page 22: Techniques for Scaling the Netflix API - QCon SF

AWS Cloud

Page 23: Techniques for Scaling the Netflix API - QCon SF
Page 24: Techniques for Scaling the Netflix API - QCon SF

Autoscaling

Page 25: Techniques for Scaling the Netflix API - QCon SF

Autoscaling

Page 26: Techniques for Scaling the Netflix API - QCon SF
Page 27: Techniques for Scaling the Netflix API - QCon SF

Techniques for Scaling the Netflix API

Agenda

• History of the Netflix API• The Cloud• Development and Testing• Resiliency• Future of the Netflix API

Page 28: Techniques for Scaling the Netflix API - QCon SF

Development / Testing Philosophy

Act fast, react fast

Page 29: Techniques for Scaling the Netflix API - QCon SF

That Doesn’t Mean We Don’t Test

• Unit tests• Functional tests• Regression scripts• Continuous integration• Capacity planning• Load / Performance tests

Page 30: Techniques for Scaling the Netflix API - QCon SF

Development(Feature & Test)

Contiuous Integration

Run Functional Tests

Deploy to Staging Env

Perform Integration

Tests

Deploy to Customers

Run Unit Tests

Page 31: Techniques for Scaling the Netflix API - QCon SF

Cloud-Based Deployment Techniques

Page 32: Techniques for Scaling the Netflix API - QCon SF

Current Code

In Production

API Requests from the Internet

Single Canary InstanceTo Test New Code with Production Traffic

(typically around 1-5% of traffic)

Problem!

Page 33: Techniques for Scaling the Netflix API - QCon SF

Current Code

In Production

API Requests from the Internet

Page 34: Techniques for Scaling the Netflix API - QCon SF

Current Code

In Production

New Code

Getting Prepared for Production

API Requests from the Internet

Page 35: Techniques for Scaling the Netflix API - QCon SF

Old Code

Prepared For Rollback

Current Code

In Production

API Requests from the Internet

Page 36: Techniques for Scaling the Netflix API - QCon SF

Old Code

Rolled Back into Production

New Code

Out of Production

API Requests from the Internet

Page 37: Techniques for Scaling the Netflix API - QCon SF

Current Code

In Production

API Requests from the Internet

Page 38: Techniques for Scaling the Netflix API - QCon SF

Current Code

In Production

New Code

Getting Prepared for Production

API Requests from the Internet

Page 39: Techniques for Scaling the Netflix API - QCon SF

Old Code

Prepared For Rollback

Current Code

In Production

API Requests from the Internet

Page 40: Techniques for Scaling the Netflix API - QCon SF

Current Code

In Production

API Requests from the Internet

Page 41: Techniques for Scaling the Netflix API - QCon SF

Run Unit Tests

Run Functional Tests

Deploy to Staging Env

Run Integration

Tests

Deploy Black Instances

Perform Canary Analysis

Deploy Canary Instance(s)

Deploy to Customers

Perform Black Analysis

Development(Feature & Test)

Continuous Integration

Page 42: Techniques for Scaling the Netflix API - QCon SF

Techniques for Scaling the Netflix API

Agenda

• History of the Netflix API• The Cloud• Development and Testing• Resiliency• Future of the Netflix API

Page 43: Techniques for Scaling the Netflix API - QCon SF

Personalization

EngineUser Info Movie

MetadataMovie Ratings

Similar Movies

API

Reviews A/B Test Engine

Page 44: Techniques for Scaling the Netflix API - QCon SF

Personalization

EngineUser Info Movie

MetadataMovie Ratings

Similar Movies

API

Reviews A/B Test Engine

Page 45: Techniques for Scaling the Netflix API - QCon SF

Personalization

EngineUser Info Movie

MetadataMovie Ratings

Similar Movies

API

Reviews A/B Test Engine

Page 46: Techniques for Scaling the Netflix API - QCon SF

Personalization

EngineUser Info Movie

MetadataMovie Ratings

Similar Movies

API

Reviews A/B Test Engine

Page 47: Techniques for Scaling the Netflix API - QCon SF

Circuit Breaker Dashboard

Page 48: Techniques for Scaling the Netflix API - QCon SF
Page 49: Techniques for Scaling the Netflix API - QCon SF

Call Volume and Health / Last 10 Seconds

Page 50: Techniques for Scaling the Netflix API - QCon SF

Call Volume / Last 2 Minutes

Page 51: Techniques for Scaling the Netflix API - QCon SF

Successful Requests

Page 52: Techniques for Scaling the Netflix API - QCon SF

Successful, But Slower Than Expected

Page 53: Techniques for Scaling the Netflix API - QCon SF

Short-Circuited Requests, Delivering Fallbacks

Page 54: Techniques for Scaling the Netflix API - QCon SF

Timeouts, Delivering Fallbacks

Page 55: Techniques for Scaling the Netflix API - QCon SF

Thread Pool & Task Queue Full, Delivering Fallbacks

Page 56: Techniques for Scaling the Netflix API - QCon SF

Exceptions, Delivering Fallbacks

Page 57: Techniques for Scaling the Netflix API - QCon SF

Error Rate# + # + # + # / (# + # + # + # + #) = Error Rate

Page 58: Techniques for Scaling the Netflix API - QCon SF

Status of Fallback Circuit

Page 59: Techniques for Scaling the Netflix API - QCon SF

Requests per Second, Over Last 10 Seconds

Page 60: Techniques for Scaling the Netflix API - QCon SF

SLA Information

Page 61: Techniques for Scaling the Netflix API - QCon SF

Personalization

EngineUser Info Movie

MetadataMovie Ratings

Similar Movies

API

Reviews A/B Test Engine

Page 62: Techniques for Scaling the Netflix API - QCon SF

Personalization

EngineUser Info Movie

MetadataMovie Ratings

Similar Movies

API

Reviews A/B Test Engine

Page 63: Techniques for Scaling the Netflix API - QCon SF

Personalization

EngineUser Info Movie

MetadataMovie Ratings

Similar Movies

API

Reviews A/B Test Engine

Page 64: Techniques for Scaling the Netflix API - QCon SF

Personalization

EngineUser Info Movie

MetadataMovie Ratings

Similar Movies

API

Reviews A/B Test Engine

Fallback

Page 65: Techniques for Scaling the Netflix API - QCon SF

Personalization

EngineUser Info Movie

MetadataMovie Ratings

Similar Movies

API

Reviews A/B Test Engine

Fallback

Page 66: Techniques for Scaling the Netflix API - QCon SF

Techniques for Scaling the Netflix API

Agenda

• History of the Netflix API• The Cloud• Development and Testing• Resiliency• Future of the Netflix API

Page 67: Techniques for Scaling the Netflix API - QCon SF

Netflix API

Page 68: Techniques for Scaling the Netflix API - QCon SF

Netflix API Requests by AudienceSupporting Streaming Devices Today

Netflix DevicesOpen API Developers

Page 69: Techniques for Scaling the Netflix API - QCon SF
Page 70: Techniques for Scaling the Netflix API - QCon SF

Redesign the API

Page 71: Techniques for Scaling the Netflix API - QCon SF

Netflix API : Requests Per Month

Jan-10 Feb-10 Mar-10 Apr-10 May-10 Jun-10 Jul-10 Aug-10 Sep-10 Oct-10 Nov-10 Dec-10 Jan-11 Feb-11 Mar-11 Apr-11 May-11 Jun-11 Jul-11 -

5

10

15

20

25

30

35

Requ

ests

in B

illio

ns

Page 72: Techniques for Scaling the Netflix API - QCon SF

Growth of the Netflix API

Over 30 Billion requests per month(Peaks at about 20,000 requests per second)

Page 73: Techniques for Scaling the Netflix API - QCon SF
Page 74: Techniques for Scaling the Netflix API - QCon SF

<catalog_titles> <number_of_results>1140</number_of_results> <start_index>0</start_index> <results_per_page>10</results_per_page> <catalog_title> <id>http://api.netflix.com/catalog/titles/movies/60021896</id><title short="Star" regular="Star"></title> <box_art small="http://alien2.netflix.com/us/boxshots/tiny/60021896.jpg"

medium="http://alien2.netflix.com/us/boxshots/small/60021896.jpg" large="http://alien2.netflix.com/us/boxshots/large/60021896.jpg"></box_art>

<link href="http://api.netflix.com/catalog/titles/movies/60021896/synopsis" rel="http://schemas.netflix.com/catalog/titles/synopsis" title="synopsis"></link>

<release_year>2001</release_year> <category scheme="http://api.netflix.com/catalog/titles/mpaa_ratings" label="NR"></category> <category scheme="http://api.netflix.com/categories/genres" label="Foreign"></category> <link href="http://api.netflix.com/catalog/titles/movies/60021896/cast"

rel="http://schemas.netflix.com/catalog/people.cast" title="cast"></link><link href="http://api.netflix.com/catalog/titles/movies/60021896/screen_formats" rel="http://schemas.netflix.com/catalog/titles/screen_formats" title="screen formats"></link <link href="http://api.netflix.com/catalog/titles/movies/60021896/languages_and_audio" rel="http://schemas.netflix.com/catalog/titles/languages_and_audio" title="languages and audio"></link> <average_rating>1.9</average_rating> <link href="http://api.netflix.com/catalog/titles/movies/60021896/similars" rel="http://schemas.netflix.com/catalog/titles.similars" title="similars"></link> <link href="http://www.netflix.com/Movie/Star/60021896" rel="alternate" title="webpage"></link> </catalog_title> <catalog_title> <id>http://api.netflix.com/catalog/titles/movies/17985448</id><title short="Lone Star" regular="Lone Star"></title> <box_art small="http://alien2.netflix.com/us/boxshots/tiny/17985448.jpg" medium="http://alien2.netflix.com/us/boxshots/small/17985448.jpg" large=""></box_art> <link href="http://api.netflix.com/catalog/titles/movies/17985448/synopsis" rel="http://schemas.netflix.com/catalog/titles/synopsis" title="synopsis"></link> <release_year>1996</release_year> <category scheme="http://api.netflix.com/catalog/titles/mpaa_ratings" label="R"></category> <category scheme="http://api.netflix.com/categories/genres" label="Drama"></category><link href="http://api.netflix.com/catalog/titles/movies/17985448/awards" rel="http://schemas.netflix.com/catalog/titles/awards" title="awards"></link> <link href="http://api.netflix.com/catalog/titles/movies/17985448/format_availability" rel="http://schemas.netflix.com/catalog/titles/format_availability" title="formats"></link> <link href="http://api.netflix.com/catalog/titles/movies/17985448/screen_formats" rel="http://schemas.netflix.com/catalog/titles/screen_formats" title="screen formats"></link> <link href="http://api.netflix.com/catalog/titles/movies/17985448/languages_and_audio" rel="http://schemas.netflix.com/catalog/titles/languages_and_audio" title="languages and audio"></link> <average_rating>3.7</average_rating> <link href="http://api.netflix.com/catalog/titles/movies/17985448/previews" rel="http://schemas.netflix.com/catalog/titles/previews" title="previews"></link> <link href="http://api.netflix.com/catalog/titles/movies/17985448/similars" rel="http://schemas.netflix.com/catalog/titles.similars" title="similars"></link> <link href="http://www.netflix.com/Movie/Lone_Star/17985448" rel="alternate" title="webpage"></link> </catalog_title></catalog_titles>

Page 75: Techniques for Scaling the Netflix API - QCon SF

{"catalog_title":{"id":"http://api.netflix.com/catalog/titles/movies/60034967","title":{"title_short":"Rosencrantz and Guildenstern Are Dead","regular":"Rosencrantz and Guildenstern Are Dead"},"maturity_level":60,"release_year":"1990","average_rating":3.7,"box_art":{"284pix_w":"http://cdn-7.nflximg.com/en_US/boxshots/ghd/60034967.jpg","110pix_w":"http://cdn-7.nflximg.com/en_US/boxshots/large/60034967.jpg","38pix_w":"http://cdn-7.nflximg.com/en_US/boxshots/tiny/60034967.jpg","64pix_w":"http://cdn-7.nflximg.com/en_US/boxshots/small/60034967.jpg","150pix_w":"http://cdn-7.nflximg.com/en_US/boxshots/150/60034967.jpg","88pix_w":"http://cdn-7.nflximg.com/en_US/boxshots/88/60034967.jpg","124pix_w":"http://cdn-7.nflximg.com/en_US/boxshots/124/60034967.jpg"},"language":"en","web_page":"http://www.netflix.com/Movie/Rosencrantz_and_Guildenstern_Are_Dead/60034967","tiny_url":"http://movi.es/ApUP9"},"meta":{"expand":["@directors","@bonus_materials","@cast","@awards","@short_synopsis","@synopsis","@box_art","@screen_formats","@"links":{"id":"http://api.netflix.com/catalog/titles/movies/60034967","languages_and_audio":"http://api.netflix.com/catalog/titles/movies/60034967/languages_and_audio","title":"http://api.netflix.com/catalog/titles/movies/60034967/title","screen_formats":"http://api.netflix.com/catalog/titles/movies/60034967/screen_formats","cast":"http://api.netflix.com/catalog/titles/movies/60034967/cast","awards":"http://api.netflix.com/catalog/titles/movies/60034967/awards","short_synopsis":"http://api.netflix.com/catalog/titles/movies/60034967/short_synopsis","box_art":"http://api.netflix.com/catalog/titles/movies/60034967/box_art","synopsis":"http://api.netflix.com/catalog/titles/movies/60034967/synopsis","directors":"http://api.netflix.com/catalog/titles/movies/60034967/directors","similars":"http://api.netflix.com/catalog/titles/movies/60034967/similars","format_availability":"http://api.netflix.com/catalog/titles/movies/60034967/format_availability"}}}

Page 76: Techniques for Scaling the Netflix API - QCon SF

Improve Efficiency of API Requests

Could it have been 5 billion requests per month? Or less?(Assuming everything else remained the same)

Page 77: Techniques for Scaling the Netflix API - QCon SF

Jan-10

Feb-10

Mar-10

Apr-10

May-10

Jun-10Jul-1

0

Aug-10

Sep-10

Oct-10

Nov-10

Dec-10

Jan-11

Feb-11

Mar-11

Apr-11

May-11

Jun-11Jul-1

10

5

10

15

20

25

30

35

Requ

est i

n Bi

llion

s

Netflix API : Requests Per Month

Page 78: Techniques for Scaling the Netflix API - QCon SF

Jan-10

Feb-10

Mar-10

Apr-10

May-10

Jun-10Jul-1

0

Aug-10

Sep-10

Oct-10

Nov-10

Dec-10

Jan-11

Feb-11

Mar-11

Apr-11

May-11

Jun-11Jul-1

10

5

10

15

20

25

30

35

Requ

est i

n Bi

llion

s

Netflix API : Requests Per Month

Page 79: Techniques for Scaling the Netflix API - QCon SF

Courtesy of John Musser, ProgrammableWeb

API Billionaires Club

5 billion API calls / day (April 2010)

3.2 billion API-delivered stories / month (October

2011)

5 billion API calls / day (October 2009)

8 billion API calls / month (Q3 2009)

3 billion API calls / month (March 2009)

13 billion API calls / day (May 2011)

Over 260 billion objects stored in S3 (January 2011)

1 billion API calls / day (October 2011)

Page 80: Techniques for Scaling the Netflix API - QCon SF

Courtesy of John Musser, ProgrammableWeb

API Billionaires Club

5 billion API calls / day (April 2010)

3.2 billion API-delivered stories / month (October

2011)

5 billion API calls / day (October 2009)

8 billion API calls / month (Q3 2009)

3 billion API calls / month (March 2009)

13 billion API calls / day (May 2011)

Over 260 billion objects stored in S3 (January 2011)

1 billion API calls / day (October 2011)

Page 81: Techniques for Scaling the Netflix API - QCon SF

Two Major Objective for API Redesign

• Improve performance for devices– Minimize network traffic (one API call, if possible)– Only deliver bytes that are needed

• Improve ability for device teams to rapidly innovate– Customized request/response patterns per device– Deployment is independent from API schedules

Page 82: Techniques for Scaling the Netflix API - QCon SF

AUTH

SETUP

TIME

QUEUE

LISTS

LIST ( i )

TITLES

CLIENT APPS API SERVER

Current Client / Server Interaction

Page 83: Techniques for Scaling the Netflix API - QCon SF

GENERIC API

CLIENT APPS API SERVER

CUSTOM SCRIPTING TIER

Future Client / Server Interaction

Page 84: Techniques for Scaling the Netflix API - QCon SF

PS3HOME

SCREENCUSTOM

ENDPOINT

CLIENT APPS API SERVER

CUSTOMSCRIPTING

TIER

Custom Scripting Tier Interaction

Owned and operated by the UI teams

AUTH

SETUP

TIME

QUEUE

LISTS

LIST ( i )

TITLES

Page 85: Techniques for Scaling the Netflix API - QCon SF
Page 86: Techniques for Scaling the Netflix API - QCon SF
Page 87: Techniques for Scaling the Netflix API - QCon SF
Page 88: Techniques for Scaling the Netflix API - QCon SF

For More Titles From a List

Page 89: Techniques for Scaling the Netflix API - QCon SF
Page 90: Techniques for Scaling the Netflix API - QCon SF

SIMPLE CATALOG REQUEST

TO API

LIST ( i )

TITLES

CLIENT APP API SERVER

GENERICSCRIPT

Generic API Interaction

Owned and operated by the API team

AUTH

CONFIG

TIME

QUEUE

LISTS

Page 91: Techniques for Scaling the Netflix API - QCon SF

LOLOMO

LIST ( i )

TITLES

AUTH

CONFIG

TIME

QUEUE

LISTS

SIMPLE CATALOG REQUEST

TO API

Technologies

CLIENT LANGUAGE

JAVAGROOVY

COMPILED INTO JVM

Page 92: Techniques for Scaling the Netflix API - QCon SF

Cassandra Cluster

API Production Servers

UI Engineers

Page 93: Techniques for Scaling the Netflix API - QCon SF

Active

1

2

34

5

6SCRIPT

REPOSITORY(DYNAMIC

DEPLOYMENT)

API SERVERAPPLICATION CODE

(REQUIRES API CODE PUSHES)

Page 94: Techniques for Scaling the Netflix API - QCon SF

Active

1

2

34

5

6SCRIPT

REPOSITORY(DYNAMIC

DEPLOYMENT)

API SERVERAPPLICATION CODE

(REQUIRES API CODE PUSHES)

7

Page 95: Techniques for Scaling the Netflix API - QCon SF

1

2

34

5

6SCRIPT

REPOSITORY(DYNAMIC

DEPLOYMENT)

API SERVERAPPLICATION CODE

(REQUIRES API CODE PUSHES)

7

Active

Page 96: Techniques for Scaling the Netflix API - QCon SF
Page 97: Techniques for Scaling the Netflix API - QCon SF
Page 98: Techniques for Scaling the Netflix API - QCon SF

If you are interested in helping us solve these problems, please contact me at:

Daniel [email protected]

@daniel_jacobsonhttp://www.linkedin.com/in/danieljacobsonhttp://www.slideshare.net/danieljacobson