Slide 1

Slide 1 text

Evolution of the Netflix API Ben Christensen Software Engineer – Edge & Playback Services at Netflix @benjchristensen ! ! ! ! http://techblog.netflix.com/ QCon San Francisco - November 2013

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

More than 40 million Subscribers in 50+ Countries and Territories

Slide 4

Slide 4 text

Netflix accounts for 33% of Peak Downstream Internet Traffic in North America Netflix subscribers are watching more than 1 billion hours a month

Slide 5

Slide 5 text

API traffic has grown from ~20 million/day in 2010 to >2 billion/day 0 500 1000 1500 2000 2010 2011 2012 Today millions of API requests per day

Slide 6

Slide 6 text

Discovery Streaming

Slide 7

Slide 7 text

Netflix API Streaming

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

At the start … 0 500 1000 1500 2000 2008 2009 2010 2011 2012 Today millions of API requests per day

Slide 10

Slide 10 text

2008 API Launch Targeted 100% at External Developers Open API Netflix Devices

Slide 11

Slide 11 text

2008 API Launch Targeted 100% at External Developers Purpose A “Thousand Flowers” of 3rd party innovation ! Audience External Developers

Slide 12

Slide 12 text

Oracle Pre-Cloud Architecture API Service Service Service Service

Slide 13

Slide 13 text

0 500 1000 1500 2000 2008 2009 2010 2011 2012 Today In 2011 … millions of API requests per day

Slide 14

Slide 14 text

99.9% Netflix Devices Open API Netflix Devices

Slide 15

Slide 15 text

Targeted at Internal Developers Open API Netflix Devices

Slide 16

Slide 16 text

Targeted at Internal Developers Purpose Enable Netflix Experience ! Audience Netflix Device and UI Teams

Slide 17

Slide 17 text

Scale & Resilience ! Performance & Innovation

Slide 18

Slide 18 text

Scale & Resilience ! Performance & Innovation

Slide 19

Slide 19 text

Netflix API Dependency A Dependency D Dependency G Dependency J Dependency M Dependency P Dependency B Dependency E Dependency H Dependency K Dependency N Dependency Q Dependency C Dependency F Dependency I Dependency L Dependency O Dependency R

Slide 20

Slide 20 text

Netflix API Dependency A Dependency D Dependency G Dependency J Dependency M Dependency P Dependency B Dependency E Dependency H Dependency K Dependency N Dependency Q Dependency C Dependency F Dependency I Dependency L Dependency O Dependency R

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

No content

Slide 25

Slide 25 text

AWS Availability Zone AWS Availability Zone AWS Availability Zone

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

User Request Dependency A Dependency D Dependency G Dependency J Dependency M Dependency P Dependency B Dependency E Dependency H Dependency K Dependency N Dependency Q Dependency C Dependency F Dependency I Dependency L Dependency O Dependency R

Slide 31

Slide 31 text

User Request Dependency A Dependency D Dependency G Dependency J Dependency M Dependency P Dependency B Dependency E Dependency H Dependency K Dependency N Dependency Q Dependency C Dependency F Dependency I Dependency L Dependency O Dependency R User request blocked by latency in single network call

Slide 32

Slide 32 text

At high volume all request threads can block in seconds User Request Dependency A Dependency D Dependency G Dependency J Dependency M Dependency P Dependency B Dependency E Dependency H Dependency K Dependency N Dependency Q Dependency C Dependency F Dependency I Dependency L Dependency O Dependency R User Request User Request User Request User Request User Request User Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Slide 33

Slide 33 text

! Dozens of dependencies. ! One going bad takes everything down. ! 99.99%30 = 99.7% uptime ! 0.3% of 1 billion = 3,000,000 failures ! 2+ hours downtime/month ! ! ! Reality is generally worse.

Slide 34

Slide 34 text

CONSTRAINTS Speed of Iteration ! Client Libraries ! Mixed Environment

Slide 35

Slide 35 text

CONSTRAINTS Speed of Iteration ! Client Libraries ! Mixed Environment

Slide 36

Slide 36 text

CONSTRAINTS Speed of Iteration ! Client Libraries ! Mixed Environment

Slide 37

Slide 37 text

CONSTRAINTS Speed of Iteration ! Client Libraries ! Mixed Environment

Slide 38

Slide 38 text

User Request Dependency A Dependency D Dependency G Dependency J Dependency M Dependency P Dependency B Dependency E Dependency H Dependency K Dependency N Dependency Q Dependency C Dependency F Dependency I Dependency L Dependency O Dependency R User Request User Request User Request User Request User Request User Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

Slide 39

Slide 39 text

cy D dency G ependency J Dependency M Dependency B Dependency E Dependency H Dependency K Dependency N Dependency C Dependency F Dependency I Dependency L Dependency O User Request User Request User Request . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Network Request - TCP/HTTP, latency, 4xx, 5xx, etc Deserialization - JSON/XML/Thrift/Protobuf/etc Logic - argument validation, caches, metrics, logging, multivariate testing, routing, etc Serialization - URL and/or body generation Logic - validation, decoration, object model, caching, metrics, logging, etc

Slide 40

Slide 40 text

"Timeout guard" daemon prio=10 tid=0x00002aaacd5e5000 nid=0x3aac runnable [0x00002aaac388f000] java.lang.Thread.State: RUNNABLE! at java.net.PlainSocketImpl.socketConnect(Native Method)! at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)! - locked <0x000000055c7e8bd8> (a java.net.SocksSocketImpl)! at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)! at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)! at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:391)! at java.net.Socket.connect(Socket.java:579)! at java.net.Socket.connect(Socket.java:528)! at java.net.Socket.(Socket.java:425)! at java.net.Socket.(Socket.java:280)! at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)! at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$1.doit(ControllerThreadSocketFactory.java:91)! at org.apache.commons.httpclient.protocol.ControllerThreadSocketFactory$SocketTask.run(ControllerThreadSocketFactory.java:158) at java.lang.Thread.run(Thread.java:722) [Sat Jun 30 04:01:37 2012] [error] proxy: HTTP: disabled connection for (127.0.0.1) > 80% of requests rejected Median Latency

Slide 41

Slide 41 text

User Request Dependency A Dependency D Dependency G Dependency J Dependency M Dependency P Dependency B Dependency E Dependency H Dependency K Dependency N Dependency Q Dependency C Dependency F Dependency I Dependency L Dependency O Dependency R

Slide 42

Slide 42 text

User Request Dependency A Dependency D Dependency G Dependency J Dependency M Dependency P Dependency B Dependency E Dependency H Dependency K Dependency N Dependency Q Dependency C Dependency F Dependency I Dependency L Dependency O Dependency R

Slide 43

Slide 43 text

User Request Dependency A Dependency D Dependency G Dependency J Dependency M Dependency P Dependency B Dependency E Dependency H Dependency K Dependency N Dependency Q Dependency C Dependency F Dependency I Dependency L Dependency O Dependency R

Slide 44

Slide 44 text

User Request Dependency A Dependency D Dependency G Dependency J Dependency M Dependency P Dependency B Dependency E Dependency H Dependency K Dependency N Dependency Q Dependency C Dependency F Dependency I Dependency L Dependency O Dependency R

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

circle color and size represent health and traffic volume

Slide 49

Slide 49 text

2 minutes of request rate to show relative changes in traffic circle color and size represent health and traffic volume

Slide 50

Slide 50 text

2 minutes of request rate to show relative changes in traffic circle color and size represent health and traffic volume hosts reporting from cluster

Slide 51

Slide 51 text

last minute latency percentiles 2 minutes of request rate to show relative changes in traffic circle color and size represent health and traffic volume hosts reporting from cluster

Slide 52

Slide 52 text

last minute latency percentiles 2 minutes of request rate to show relative changes in traffic circle color and size represent health and traffic volume hosts reporting from cluster Circuit-breaker status

Slide 53

Slide 53 text

last minute latency percentiles Request rate 2 minutes of request rate to show relative changes in traffic circle color and size represent health and traffic volume hosts reporting from cluster Circuit-breaker status

Slide 54

Slide 54 text

Error percentage of last 10 seconds last minute latency percentiles Request rate 2 minutes of request rate to show relative changes in traffic circle color and size represent health and traffic volume hosts reporting from cluster Error percentage of last 10 seconds Circuit-breaker status

Slide 55

Slide 55 text

last minute latency percentiles Request rate 2 minutes of request rate to show relative changes in traffic circle color and size represent health and traffic volume hosts reporting from cluster Error percentage of last 10 seconds Rolling 10 second counters with 1 second granularity Failures/Exceptions Thread-pool Rejections Thread timeouts Successes Short-circuited (rejected) Circuit-breaker status

Slide 56

Slide 56 text

User Request Dependency A Dependency D Dependency G Dependency J Dependency M Dependency P Dependency B Dependency E Dependency H Dependency K Dependency N Dependency Q Dependency C Dependency F Dependency I Dependency L Dependency O Dependency R

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

Zuul Routing Layer Canary vs Baseline Squeeze Production "Coalmine"

Slide 59

Slide 59 text

Zuul Routing Layer Canary vs Baseline Squeeze Production "Coalmine"

Slide 60

Slide 60 text

Zuul Routing Layer Canary vs Baseline Squeeze Production "Coalmine"

Slide 61

Slide 61 text

Zuul Routing Layer Canary vs Baseline Squeeze Production "Coalmine"

Slide 62

Slide 62 text

Zuul Routing Layer Canary vs Baseline Squeeze Production "Coalmine"

Slide 63

Slide 63 text

User Request Dependency A Dependency D Dependency G Dependency J Dependency M Dependency P Dependency B Dependency E Dependency H Dependency K Dependency N Dependency Q Dependency C Dependency F Dependency I Dependency L Dependency O Dependency R System Relationship Over Network without Bulkhead

Slide 64

Slide 64 text

Zuul Routing Layer Canary vs Baseline Squeeze Production "Coalmine"

Slide 65

Slide 65 text

Zuul Routing Layer Canary vs Baseline Squeeze Production "Coalmine"

Slide 66

Slide 66 text

No content

Slide 67

Slide 67 text

No content

Slide 68

Slide 68 text

No content

Slide 69

Slide 69 text

No content

Slide 70

Slide 70 text

No content

Slide 71

Slide 71 text

No content

Slide 72

Slide 72 text

No content

Slide 73

Slide 73 text

No content

Slide 74

Slide 74 text

Predictive + Reactive Auto-Scaling

Slide 75

Slide 75 text

No content

Slide 76

Slide 76 text

No content

Slide 77

Slide 77 text

No content

Slide 78

Slide 78 text

No content

Slide 79

Slide 79 text

No content

Slide 80

Slide 80 text

No content

Slide 81

Slide 81 text

No content

Slide 82

Slide 82 text

No content

Slide 83

Slide 83 text

Scale & Resilience ! Performance & Innovation

Slide 84

Slide 84 text

Netflix API Dependency A Dependency D Dependency G Dependency J Dependency M Dependency P Dependency B Dependency E Dependency H Dependency K Dependency N Dependency Q Dependency C Dependency F Dependency I Dependency L Dependency O Dependency R

Slide 85

Slide 85 text

Netflix API Dependency A Dependency D Dependency G Dependency J Dependency M Dependency P Dependency B Dependency E Dependency H Dependency K Dependency N Dependency Q Dependency C Dependency F Dependency I Dependency L Dependency O Dependency R

Slide 86

Slide 86 text

One Size Fits All RESTful API 0 500 1000 1500 2000 2010 2011 2012 Today millions of API requests per day

Slide 87

Slide 87 text

One Size Fits All RESTful API 0 500 1000 1500 2000 2010 2011 2012 Today millions of API requests per day

Slide 88

Slide 88 text

One Size Fits All RESTful API 0 500 1000 1500 2000 2010 2011 2012 Today millions of API requests per day 1000+ Devices

Slide 89

Slide 89 text

We wanted to re-architecture our call patterns ...

Slide 90

Slide 90 text

... to collapse network traffic into coarse API calls ... nested, conditional, concurrent execution

Slide 91

Slide 91 text

... and we wanted to allow anybody to create endpoints, not just the “API Team”

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

Concurrency without each engineer reading and re-reading this → ! (awesome book ... everybody isn’t going to - or should have to - read it though, that’s the point)

Slide 94

Slide 94 text

Owner of api should retain control of concurrency behavior.

Slide 95

Slide 95 text

What if the implementation needs to change from synchronous to asynchronous? ! How should the client execute that method without blocking? spawn a thread? public  Data  getData(); Owner of api should retain control of concurrency behavior.

Slide 96

Slide 96 text

public  void  getData(Callback  c);   ! public  Future  getData();   ! public  Future>>  getData();   ! ! other options ... ? public  Data  getData();

Slide 97

Slide 97 text

Iterable pull Observable push T next() throws Exception returns; onNext(T) onError(Exception) onCompleted() Reactive Programming with Rx

Slide 98

Slide 98 text

Iterable pull Observable push T next() throws Exception returns; onNext(T) onError(Exception) onCompleted() (Functional) Reactive Programming with RxJava

Slide 99

Slide 99 text

Iterable pull Observable push T next() throws Exception returns; onNext(T) onError(Exception) onCompleted() (Functional) Reactive Programming with RxJava

Slide 100

Slide 100 text

Iterable pull Observable push T next() throws Exception returns; onNext(T) onError(Exception) onCompleted() (Functional) Reactive Programming with RxJava

Slide 101

Slide 101 text

Iterable pull Observable push T next() throws Exception returns; onNext(T) onError(Exception) onCompleted() !  //  Iterable      //  that  contains  75  Strings    getDataFromLocalMemory()      .skip(10)      .take(5)      .map({  s  -­‐>          return  s  +  "_transformed"})      .forEach(            {  println  "next  =>  "  +  it})   !  //  Observable      //  that  emits  75  Strings    getDataFromNetwork()      .skip(10)      .take(5)      .map({  s  -­‐>          return  s  +  "_transformed"})      .subscribe(            {  println  "onNext  =>  "  +  it})  

Slide 102

Slide 102 text

Iterable pull Observable push T next() throws Exception returns; onNext(T) onError(Exception) onCompleted() !  //  Iterable      //  that  contains  75  Strings    getDataFromLocalMemory()      .skip(10)      .take(5)      .map({  s  -­‐>          return  s  +  "_transformed"})      .forEach(            {  println  "onNext  =>  "  +  it})   !  //  Observable      //  that  emits  75  Strings    getDataFromNetwork()      .skip(10)      .take(5)      .map({  s  -­‐>          return  s  +  "_transformed"})      .subscribe(            {  println  "onNext  =>  "  +  it})  

Slide 103

Slide 103 text

Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData()

Slide 104

Slide 104 text

Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData() String s = getData(args); if (s.equals(x)) { // do something } else { // do something else }

Slide 105

Slide 105 text

Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData() Iterable values = getData(args); for (String s : values) { if (s.equals(x)) { // do something } else { // do something else } }

Slide 106

Slide 106 text

Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData() Future s = getData(args); if (s.get().equals(x)) { // do something } else { // do something else }

Slide 107

Slide 107 text

Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData() Future s = getData(args); if (s.get().equals(x)) { // do something } else { // do something else }

Slide 108

Slide 108 text

Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData() Future s = getData(args); Futures.addCallback(s, new FutureCallback { public void onSuccess(String s) { if (s.equals(x)) { // do something } else { // do something else } } }, executor);

Slide 109

Slide 109 text

Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData() Future s = getData(args); Futures.addCallback(s, new FutureCallback { public void onSuccess(String s) { if (s.equals(x)) { // do something } else { // do something else } } }, executor);

Slide 110

Slide 110 text

Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData() Future s = getData(args); Futures.addCallback(s, new FutureCallback { public void onSuccess(String s) { if (s.equals(x)) { // do something } else { // do something else } } }, executor);

Slide 111

Slide 111 text

Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData() CompletableFuture s = getData(args); s.thenApply((v) -> { if (v.equals(x)) { // do something } else { // do something else } });

Slide 112

Slide 112 text

Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData() CompletableFuture s = getData(args); s.thenApply((v) -> { if (v.equals(x)) { // do something } else { // do something else } });

Slide 113

Slide 113 text

Future s = getData(args); s.map({ s -> if (s.equals(x)) { // do something } else { // do something else } }); Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData()

Slide 114

Slide 114 text

Future s = getData(args); s.map({ s -> if (s.equals(x)) { // do something } else { // do something else } }); Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData()

Slide 115

Slide 115 text

Future s = getData(args); s.map({ s -> if (s.equals(x)) { // do something } else { // do something else } }); Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData()

Slide 116

Slide 116 text

Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData() Observable s = getData(args); s.map({ s -> if (s.equals(x)) { // do something } else { // do something else } });

Slide 117

Slide 117 text

Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData() Observable s = getData(args); s.map({ s -> if (s.equals(x)) { // do something } else { // do something else } });

Slide 118

Slide 118 text

Single Multiple Sync T getData() Iterable getData() Async Future getData() Observable getData() Observable s = getData(args); s.map({ s -> if (s.equals(x)) { // do something } else { // do something else } });

Slide 119

Slide 119 text

class  VideoService  {        def  VideoList  getPersonalizedListOfMovies(userId);        def  VideoBookmark  getBookmark(userId,  videoId);        def  VideoRating  getRating(userId,  videoId);        def  VideoMetadata  getMetadata(videoId);   } class  VideoService  {        def  Observable  getPersonalizedListOfMovies(userId);        def  Observable  getBookmark(userId,  videoId);        def  Observable  getRating(userId,  videoId);        def  Observable  getMetadata(videoId);   } ... create an observable api: instead of a blocking api ...

Slide 120

Slide 120 text

“a library for composing asynchronous and event-based programs using observable sequences for the Java VM” A Java port of Rx (Reactive Extensions) https://rx.codeplex.com (.Net and Javascript by Microsoft) RxJava http://github.com/Netflix/RxJava

Slide 121

Slide 121 text

client code treats all interactions with the api as asynchronous ! ! the api implementation chooses whether something is blocking or non-blocking and what resources it uses

Slide 122

Slide 122 text

No content

Slide 123

Slide 123 text

No content

Slide 124

Slide 124 text

No content

Slide 125

Slide 125 text

No content

Slide 126

Slide 126 text

No content

Slide 127

Slide 127 text

No content

Slide 128

Slide 128 text

Netflix API Device Server Optimize for Each Device. Leverage the Server

Slide 129

Slide 129 text

Code

Slide 130

Slide 130 text

SDK for API Web Service Development

Slide 131

Slide 131 text

SDK for API Web Service Development

Slide 132

Slide 132 text

SDK for API Web Service Development

Slide 133

Slide 133 text

api.servletResponse.writer.print("Hello")

Slide 134

Slide 134 text

api.servletResponse.writer.print("Hello") $runScript.py -e PROD sample.groovy Hello ################################################################################################ ####### Script Logger (enabled via debug=true request parameter) ################################################################################################ [0ms] INFO: User => NULL ################################################################################################ ####### Script Logger (enabled via debug=true request parameter) ################################################################################################

Slide 135

Slide 135 text

api.servletResponse.writer.print("Hello") $runScript.py -e PROD sample.groovy Hello ################################################################################################ ####### Script Logger (enabled via debug=true request parameter) ################################################################################################ [0ms] INFO: User => NULL ################################################################################################ ####### Script Logger (enabled via debug=true request parameter) ################################################################################################

Slide 136

Slide 136 text

api.servletResponse.writer.print("Hello") $runScript.py -e PROD sample.groovy Hello ################################################################################################ ####### Script Logger (enabled via debug=true request parameter) ################################################################################################ [0ms] INFO: User => NULL ################################################################################################ ####### Script Logger (enabled via debug=true request parameter) ################################################################################################

Slide 137

Slide 137 text

api.servletResponse.writer.print("Hello") $runScript.py -e PROD sample.groovy Hello ################################################################################################ ####### Script Logger (enabled via debug=true request parameter) ################################################################################################ [0ms] INFO: User => NULL ################################################################################################ ####### Script Logger (enabled via debug=true request parameter) ################################################################################################

Slide 138

Slide 138 text

api.servletResponse.writer.print("Hello") $runScript.py -e PROD sample.groovy Hello ################################################################################################ ####### Script Logger (enabled via debug=true request parameter) ################################################################################################ [0ms] INFO: User => NULL ################################################################################################ ####### Script Logger (enabled via debug=true request parameter) ################################################################################################

Slide 139

Slide 139 text

api.servletResponse.writer.print("Hello") $runScript.py -e PROD sample.groovy Hello ################################################################################################ ####### Script Logger (enabled via debug=true request parameter) ################################################################################################ [0ms] INFO: User => NULL ################################################################################################ ####### Script Logger (enabled via debug=true request parameter) ################################################################################################

Slide 140

Slide 140 text

public class HelloEndpoint extends APIEndpoint { @Override public void execute(APIRequest api) throws Throwable { // get a request parameter from servlet request String alias = api.servletRequest.getParameter("name"); ! // set content type and write something to servlet response api.servletResponse.setContentType("application/json"); api.servletResponse.writer.print( JsonUtility.toJson( [ alias : alias, name : api.user.firstName ] ) ) ! } }

Slide 141

Slide 141 text

public class HelloEndpoint extends APIEndpoint { @Override public void execute(APIRequest api) throws Throwable { // get a request parameter from servlet request String alias = api.servletRequest.getParameter("name"); ! // set content type and write something to servlet response api.servletResponse.setContentType("application/json"); api.servletResponse.writer.print( JsonUtility.toJson( [ alias : alias, name : api.user.firstName ] ) ) ! } } runScript.py -e TEST --userId 1189658154 --args "name=bob" HelloEndpoint.groovy

Slide 142

Slide 142 text

public class HelloEndpoint extends APIEndpoint { @Override public void execute(APIRequest api) throws Throwable { // get a request parameter from servlet request String alias = api.servletRequest.getParameter("name"); ! // set content type and write something to servlet response api.servletResponse.setContentType("application/json"); api.servletResponse.writer.print( JsonUtility.toJson( [ alias : alias, name : api.user.firstName ] ) ) ! } } runScript.py -e TEST --userId 1189658154 --args "name=bob" HelloEndpoint.groovy {"alias":"bob","name":"Old"}

Slide 143

Slide 143 text

public class HelloEndpoint extends APIEndpoint { @Override public void execute(APIRequest api) throws Throwable { // get a request parameter from servlet request String alias = api.servletRequest.getParameter("name"); ! // set content type and write something to servlet response api.servletResponse.setContentType("application/json"); api.servletResponse.writer.print( JsonUtility.toJson( [ alias : alias, name : api.user.firstName ] ) ) ! } } runScript.py -e TEST --userId 1189658154 --args "name=bob" HelloEndpoint.groovy {"alias":"bob","name":"Old"}

Slide 144

Slide 144 text

public class HelloEndpoint extends APIEndpoint { @Override public void execute(APIRequest api) throws Throwable { // get a request parameter from servlet request String alias = api.servletRequest.getParameter("name"); ! // set content type and write something to servlet response api.servletResponse.setContentType("application/json"); api.servletResponse.writer.print( JsonUtility.toJson( [ alias : alias, name : api.user.firstName ] ) ) ! } } runScript.py -e TEST --userId 1189658154 --args "name=bob" HelloEndpoint.groovy {"alias":"bob","name":"Old"}

Slide 145

Slide 145 text

public class HelloEndpoint extends APIEndpoint { @Override public void execute(APIRequest api) throws Throwable { // get a request parameter from servlet request String alias = api.servletRequest.getParameter("name"); ! // set content type and write something to servlet response api.servletResponse.setContentType("application/json"); api.servletResponse.writer.print( JsonUtility.toJson( [ alias : alias, name : api.user.firstName ] ) ) ! } } runScript.py -e TEST --userId 1189658154 --args "name=bob" HelloEndpoint.groovy {"alias":"bob","name":"Old"}

Slide 146

Slide 146 text

public class HelloEndpoint extends APIEndpoint { @Override public void execute(APIRequest api) throws Throwable { // get a request parameter from servlet request String alias = api.servletRequest.getParameter("name"); ! // set content type and write something to servlet response api.servletResponse.setContentType("application/json"); api.servletResponse.writer.print( JsonUtility.toJson( [ alias : alias, name : api.user.firstName ] ) ) ! } } runScript.py -e TEST --userId 1189658154 --args "name=bob" HelloEndpoint.groovy {"alias":"bob","name":"Old"}

Slide 147

Slide 147 text

public class HelloEndpoint extends APIEndpoint { @Override public void execute(APIRequest api) throws Throwable { // get a request parameter from servlet request String alias = api.servletRequest.getParameter("name"); ! // set content type and write something to servlet response api.servletResponse.setContentType("application/json"); api.servletResponse.writer.print( JsonUtility.toJson( [ alias : alias, name : api.user.firstName ] ) ) ! } } runScript.py -e TEST --userId 1189658154 --args "name=bob" HelloEndpoint.groovy {"alias":"bob","name":"Old"}

Slide 148

Slide 148 text

public Observable getVideoSummary(APIVideo video) { // get id, title def seed = [id: video.id, title : video.getTitle(APIVideo.TitleType.REGULAR)] ! // get bookmark def bookmarkObservable = getBookmark(video) ! // get artwork def artworkObservable = getArtworkImageUrl(video) ! // merge them and accumulate into the seed. return Observable.merge(bookmarkObservable, artworkObservable) .reduce(seed, { aggregate, current -> aggregate << current}) .map({ [ (video.id.toString()) : it]}) }

Slide 149

Slide 149 text

public Observable getVideoSummary(APIVideo video) { // get id, title def seed = [id: video.id, title : video.getTitle(APIVideo.TitleType.REGULAR)] ! // get bookmark def bookmarkObservable = getBookmark(video) ! // get artwork def artworkObservable = getArtworkImageUrl(video) ! // merge them and accumulate into the seed. return Observable.merge(bookmarkObservable, artworkObservable) .reduce(seed, { aggregate, current -> aggregate << current}) .map({ [ (video.id.toString()) : it]}) }

Slide 150

Slide 150 text

public Observable getVideoSummary(APIVideo video) { // get id, title def seed = [id: video.id, title : video.getTitle(APIVideo.TitleType.REGULAR)] ! // get bookmark def bookmarkObservable = getBookmark(video) ! // get artwork def artworkObservable = getArtworkImageUrl(video) ! // merge them and accumulate into the seed. return Observable.merge(bookmarkObservable, artworkObservable) .reduce(seed, { aggregate, current -> aggregate << current}) .map({ [ (video.id.toString()) : it]}) }

Slide 151

Slide 151 text

public Observable getVideoSummary(APIVideo video) { // get id, title def seed = [id: video.id, title : video.getTitle(APIVideo.TitleType.REGULAR)] ! // get bookmark def bookmarkObservable = getBookmark(video) ! // get artwork def artworkObservable = getArtworkImageUrl(video) ! // merge them and accumulate into the seed. return Observable.merge(bookmarkObservable, artworkObservable) .reduce(seed, { aggregate, current -> aggregate << current}) .map({ [ (video.id.toString()) : it]}) }

Slide 152

Slide 152 text

public Observable getVideoSummary(APIVideo video) { // get id, title def seed = [id: video.id, title : video.getTitle(APIVideo.TitleType.REGULAR)] ! // get bookmark def bookmarkObservable = getBookmark(video) ! // get artwork def artworkObservable = getArtworkImageUrl(video) ! // merge them and accumulate into the seed. return Observable.merge(bookmarkObservable, artworkObservable) .reduce(seed, { aggregate, current -> aggregate << current}) .map({ [ (video.id.toString()) : it]}) }

Slide 153

Slide 153 text

public Observable getVideoSummary(APIVideo video) { // get id, title def seed = [id: video.id, title : video.getTitle(APIVideo.TitleType.REGULAR)] ! // get bookmark def bookmarkObservable = getBookmark(video) ! // get artwork def artworkObservable = getArtworkImageUrl(video) ! // merge them and accumulate into the seed. return Observable.merge(bookmarkObservable, artworkObservable) .reduce(seed, { aggregate, current -> aggregate << current}) .map({ [ (video.id.toString()) : it]}) }

Slide 154

Slide 154 text

public Observable getVideoSummary(APIVideo video) { // get id, title def seed = [id: video.id, title : video.getTitle(APIVideo.TitleType.REGULAR)] ! // get bookmark def bookmarkObservable = getBookmark(video) ! // get artwork def artworkObservable = getArtworkImageUrl(video) ! // merge them and accumulate into the seed. return Observable.merge(bookmarkObservable, artworkObservable) .reduce(seed, { aggregate, current -> aggregate << current}) .map({ [ (video.id.toString()) : it]}) }

Slide 155

Slide 155 text

$ uploadScript.py -e TEST /test/hello sample.groovy { "active": false, "allocationPercentage": 0, "creationDate": "Mon Nov 11 05:38:51 UTC 2013", "revision": 1, "userAuthorizationRequired": true, "userAuthorizationType": "https" }

Slide 156

Slide 156 text

$ uploadScript.py -e TEST /test/hello sample.groovy { "active": false, "allocationPercentage": 0, "creationDate": "Mon Nov 11 05:38:51 UTC 2013", "revision": 1, "userAuthorizationRequired": true, "userAuthorizationType": "https" }

Slide 157

Slide 157 text

$ uploadScript.py -e TEST /test/hello sample.groovy { "active": false, "allocationPercentage": 0, "creationDate": "Mon Nov 11 05:40:26 UTC 2013", "revision": 2, "userAuthorizationRequired": true, "userAuthorizationType": "https" }

Slide 158

Slide 158 text

$ uploadScript.py -e TEST /test/hello sample.groovy { "active": false, "allocationPercentage": 0, "creationDate": "Mon Nov 11 05:40:26 UTC 2013", "revision": 2, "userAuthorizationRequired": true, "userAuthorizationType": "https" } $ activateScript.py -e TEST --revision 2 /test/hello { "active": true, "allocationPercentage": 100, "creationDate": "Mon Nov 11 05:40:26 UTC 2013", "previousRevision": null, "revision": 2, "userAuthorizationRequired": true, "userAuthorizationType": "https" }

Slide 159

Slide 159 text

$ uploadScript.py -e TEST /test/hello sample.groovy { "active": false, "allocationPercentage": 0, "creationDate": "Mon Nov 11 05:40:26 UTC 2013", "revision": 2, "userAuthorizationRequired": true, "userAuthorizationType": "https" } $ activateScript.py -e TEST --revision 2 /test/hello { "active": true, "allocationPercentage": 100, "creationDate": "Mon Nov 11 05:40:26 UTC 2013", "previousRevision": null, "revision": 2, "userAuthorizationRequired": true, "userAuthorizationType": "https" }

Slide 160

Slide 160 text

$ uploadScript.py -e TEST /test/hello sample.groovy { "active": false, "allocationPercentage": 0, "creationDate": "Mon Nov 11 05:40:26 UTC 2013", "revision": 2, "userAuthorizationRequired": true, "userAuthorizationType": "https" } $ activateScript.py -e TEST --revision 2 /test/hello { "active": true, "allocationPercentage": 100, "creationDate": "Mon Nov 11 05:40:26 UTC 2013", "previousRevision": null, "revision": 2, "userAuthorizationRequired": true, "userAuthorizationType": "https" }

Slide 161

Slide 161 text

$ uploadScript.py -e TEST /test/hello sample.groovy { "active": false, "allocationPercentage": 0, "creationDate": "Mon Nov 11 05:40:26 UTC 2013", "revision": 2, "userAuthorizationRequired": true, "userAuthorizationType": "https" } $ activateScript.py -e TEST --revision 2 /test/hello { "active": true, "allocationPercentage": 100, "creationDate": "Mon Nov 11 05:40:26 UTC 2013", "previousRevision": null, "revision": 2, "userAuthorizationRequired": true, "userAuthorizationType": "https" }

Slide 162

Slide 162 text

$ uploadScript.py -e TEST /test/hello sample.groovy { "active": false, "allocationPercentage": 0, "creationDate": "Mon Nov 11 05:40:26 UTC 2013", "revision": 2, "userAuthorizationRequired": true, "userAuthorizationType": "https" } $ activateScript.py -e TEST --revision 3 /test/hello { "active": true, "allocationPercentage": 100, "creationDate": "Mon Nov 11 05:42:05 UTC 2013", "previousRevision": 2, "revision": 3, "userAuthorizationRequired": true, "userAuthorizationType": "https" }

Slide 163

Slide 163 text

Future

Slide 164

Slide 164 text

millions of API requests per day 0 500 1000 1500 2000 2008 2009 2010 2011 2012 Today

Slide 165

Slide 165 text

No content

Slide 166

Slide 166 text

No content

Slide 167

Slide 167 text

No content

Slide 168

Slide 168 text

No content

Slide 169

Slide 169 text

No content

Slide 170

Slide 170 text

No content

Slide 171

Slide 171 text

No content

Slide 172

Slide 172 text

/ps3/home Dependency F 10 Threads Dependency G 10 Threads Dependency H 10 Threads Dependency I 5 Threads Dependency J 8 Threads Dependency A 10 Threads Dependency B 8 Threads Dependency C 10 Threads Dependency D 15 Threads Dependency E 5 Threads Dependency K 15 Threads Dependency L 4 Threads Dependency M 5 Threads Dependency N 10 Threads Dependency O 10 Threads Dependency P 10 Threads Dependency Q 8 Threads Dependency R 10 Threads Dependency S 8 Threads Dependency T 10 Threads /android/home /tv/home Functional Reactive Dynamic Endpoints Asynchronous Java API

Slide 173

Slide 173 text

/ps3/home Dependency F 10 Threads Dependency G 10 Threads Dependency H 10 Threads Dependency I 5 Threads Dependency J 8 Threads Dependency A 10 Threads Dependency B 8 Threads Dependency C 10 Threads Dependency D 15 Threads Dependency E 5 Threads Dependency K 15 Threads Dependency L 4 Threads Dependency M 5 Threads Dependency N 10 Threads Dependency O 10 Threads Dependency P 10 Threads Dependency Q 8 Threads Dependency R 10 Threads Dependency S 8 Threads Dependency T 10 Threads /android/home /tv/home Functional Reactive Dynamic Endpoints Asynchronous Java API Hystrix fault-isolation layer

Slide 174

Slide 174 text

+ Observable  u  =  new  GetUserCommand(id).observe();   Observable  g  =  new  GetGeoCommand(request).observe();   ! Observable.zip(u,  g,  {user,  geo  -­‐>                    return  [username:  user.getUsername(),                                    currentLocation:  geo.getCounty()]         }) RxJava in Hystrix 1.3+ https://github.com/Netflix/Hystrix

Slide 175

Slide 175 text

No content

Slide 176

Slide 176 text

No content

Slide 177

Slide 177 text

Optimizing the Netflix API http://techblog.netflix.com/2013/01/optimizing-netflix-api.html ! Why REST Keeps Me Up At Night http://blog.programmableweb.com/2012/05/15/why-rest-keeps-me-up-at-night/ ! Functional Reactive in the Netflix API with RxJava http://techblog.netflix.com/2013/02/rxjava-netflix-api.html ! Application Resilience in a Service-oriented Architecture http://programming.oreilly.com/2013/06/application-resilience-in-a-service-oriented-architecture.html ! Netflix API on Tech Blog http://techblog.netflix.com/search/label/api jobs.netflix.com Ben Christensen @benjchristensen http://www.linkedin.com/in/benjchristensen