Share
Embed
CodeMentor April 2015
This was presented as a hangout session on codementor:
This presentation introduces reactive IPC, it's core tenants and what value adds it brings vis-a-vis traditional IPC technologies.
Nitesh Kant
April 20, 2015
Transcript
115 slides
-
Nitesh Kant - @NiteshKant - Software Engineer, Cloud Platform, Netflix
Reactive IPC Revolutionize your Microservices -
Nitesh Kant Who Am I? ❖ Engineer, Cloud Platform, Netflix.
❖ Leading Reactive IPC @Netflix ❖ Core contributor, RxNetty* ❖ Contributor, Eureka** ❖ Suffers with OCD => API design * https://github.com/ReactiveX/RxNetty ** https://github.com/Netflix/eureka @NiteshKant -
Calling Home One of many HTTP calls to deliver Netflix.
http://www.netflix.com/WiHome -
IPC Any call made outside of your process to a
remote machine or local, is an IPC call. -
Synchronous systems Consuming a resource (thread) per user request does
bad things to you. http://techblog.netflix.com/2012/02/fault-tolerance-in-high-volume.html -
Synchronous systems Consuming a resource (thread) per user request does
bad things to you. http://techblog.netflix.com/2012/02/fault-tolerance-in-high-volume.html You isolate yourself by introducing a queuing point. -
Synchronous systems Consuming a resource (thread) per user request does
bad things to you. http://techblog.netflix.com/2012/02/fault-tolerance-in-high-volume.html You isolate yourself by introducing a queuing point. But then you are limited by the number of threads in the system. -
Asynchronous systems Multiple connections/requests multiplexed on a single thread (Eventloop).
Eventloop (Inbound) Connection Connection Connection Connection Connection Eventloop (Outbound) Connection Connection Connection Connection Connection Application Code -
Asynchronous systems Multiple connections/requests multiplexed on a single thread (Eventloop).
An Eventloop only does CPU work and does not block. Eventloop (Inbound) Connection Connection Connection Connection Connection Eventloop (Outbound) Connection Connection Connection Connection Connection Application Code -
Asynchronous systems Multiple connections/requests multiplexed on a single thread (Eventloop).
An Eventloop only does CPU work and does not block. A single bad dependency/connection does not bring down the system. Eventloop (Inbound) Connection Connection Connection Connection Connection Eventloop (Outbound) Connection Connection Connection Connection Connection Application Code -
Asynchronous systems Multiple connections/requests multiplexed on a single thread (Eventloop).
An Eventloop only does CPU work and does not block. As many Eventloops as CPUs. A single bad dependency/connection does not bring down the system. Eventloop (Inbound) Connection Connection Connection Connection Connection Eventloop (Outbound) Connection Connection Connection Connection Connection Application Code Eventloop (Inbound) Connection Connection Connection Connection Connection Eventloop (Outbound) Connection Connection Connection Connection Connection Eventloop (Inbound) Connection Connection Connection Connection Connection Eventloop (Outbound) Connection Connection Connection Connection Connection -
Movie Service User Service Service discovery Which are the instances
of User Service? -
Movie Service User Service Service discovery Which are the instances
of User Service? Instances I1, I2, I3 -
Movie Service User Service Service discovery Which are the instances
of User Service? Instances I1, I2, I3 Any changes? Nope -
Movie Service User Service Service discovery Which are the instances
of User Service? Instances I1, I2, I3 Any changes? Nope Any changes? I2 is dead -
Movie Service User Service Service discovery Which are the instances
of User Service? Instances I1, I2, I3 Any changes? Nope Any changes? I2 is dead Somewhere here I2 died -
Movie Service User Service Service discovery Which are the instances
of User Service? Instances I1, I2, I3 Any changes? Nope Any changes? I2 is dead Somewhere here I2 died -
Movie Service User Service Service discovery I am interested in
User Service instances. -
Movie Service User Service Service discovery I am interested in
User Service instances. Instances I1, I2, I3 -
Movie Service User Service Service discovery I am interested in
User Service instances. Instances I1, I2, I3 Any changes? Nope X -
Movie Service User Service Service discovery I am interested in
User Service instances. Instances I1, I2, I3 I2 died -
Service discovery IPC Reactive IPC Pull based discovery Push based
discovery Implicit multi-stage delays -
Movie Service User Service Service discovery Which are the instances
of User Service? Instances I1, I2, I3 Any changes? Nope Any changes? I2 is dead Somewhere here I2 died -
Service discovery IPC Reactive IPC Pull based discovery Push based
discovery Implicit multi-stage delays Instantaneous updates -
As soon as an instance is shutdown, it is removed
from the clients using them. -
Delivering Netflix Edge Service Personalized catalog service Ratings Service Video
Metadata Service Bookmarks Service Disclaimer: This is an example and not an exact representation of the processing -
Edge Service Personalized catalog service Ratings Service Video Metadata Service
Bookmarks Service Disclaimer: This is an example and not an exact representation of the processing -
Edge Service Personalized catalog service Ratings Service Video Metadata Service
Bookmarks Service Disclaimer: This is an example and not an exact representation of the processing X User cancellation -
Edge Service Personalized catalog service Ratings Service Video Metadata Service
Bookmarks Service Disclaimer: This is an example and not an exact representation of the processing X User cancellation X X X X -
Delivering Netflix Edge Service Video Metadata Service Disclaimer: This is
an example and not an exact representation of the processing -
Edge Service Video Metadata Service Disclaimer: This is an example
and not an exact representation of the processing Get 100 videos details (Batch API) Send Video details -
Edge Service Video Metadata Service Disclaimer: This is an example
and not an exact representation of the processing Get 100 videos details (Batch API) Send Video details }X n -
Edge Service Video Metadata Service Disclaimer: This is an example
and not an exact representation of the processing Get 100 videos details (Batch API) Send Video details }X n That’s too much of data! -
Control IPC Reactive IPC No optimal cancellations Built-in Cancellations Transport
level flow-control Application flow-control -
Edge Service Video Metadata Service Disclaimer: This is an example
and not an exact representation of the processing Get 100 videos details (Batch API) -
Edge Service Video Metadata Service Disclaimer: This is an example
and not an exact representation of the processing Get 100 videos details (Batch API) Request 5 -
Edge Service Video Metadata Service Disclaimer: This is an example
and not an exact representation of the processing Get 100 videos details (Batch API) Request 5 Send 5 -
Edge Service Video Metadata Service Disclaimer: This is an example
and not an exact representation of the processing Get 100 videos details (Batch API) Request 5 Send 5 Request 5 Send 5 -
Edge Service Video Metadata Service Disclaimer: This is an example
and not an exact representation of the processing Get 100 videos details (Batch API) Request 5 Send 5 Request 5 Send 5 -
Client lib Failure detector Is Instance I1 healthy? Yep Any
client library -
Client lib Failure detector Is Instance I1 healthy? Yep Still
healthy? Yep Any client library -
Client lib Failure detector Is Instance I1 healthy? Yep Still
healthy? Nope Any client library Still healthy? Yep -
Client lib Failure detector Is Instance I1 healthy? Yep Still
healthy? Nope Any client library Still healthy? Yep Somewhere here I1 died -
Client lib Failure detector Is Instance I1 healthy? Yep Still
healthy? Nope Any client library Still healthy? Yep Somewhere here I1 died Errors & Retries -
Client lib Failure detector I am using I1, tell me
when it dies Any client library -
Client lib Failure detector I am using I1, tell me
when it dies I1 died Any client library -
Client lib Failure detector I am using I1, tell me
when it dies I1 died Any client library Minimal Errors & Retries -
RxJava A library for composing asynchronous and event-based programs using
observable sequences for the Java VM. http://github.com/ReactiveX/RxJava -
Single Multiple Sync T getData() Iterable<T> getData() Stream<T> getData() Async
Future<T> getData() Observable<T> getData() -
Subscription sub = Observable.range(1, 100) .subscribe(System.out::println, Throwable::printStackTrace, () -> System.out.println("Done"));
. . . // Later based on some other event sub.unsubscribe() -
Your Service as an Observable.* * Courtesy: “Your Server as
a function” - Marius Eriksen -
Delivering Netflix Edge Service Personalized catalog service Ratings Service Video
Metadata Service Bookmarks Service Disclaimer: This is an example and not an exact representation of the processing -
return HttpServer.newServer(port) .start((req, resp) -> catalogClient.createGet("http://catalogservice/catalog") .switchMap(catalogResp -> resp.sendHeaders() .write(catalogResp.flatMap(catalog
-> Catalog::videos) .flatMap(video -> Observable.zip(bookmarkClient.createGet("http://bookmarkservice/" + video.id()) .<Bookmark>flatMap(HttpClientResponse::getContent), ratingClient.createGet("http://ratingsservice/" + video.id()) .<Rating>flatMap(HttpClientResponse::getContent), metadataClient.createGet("http://metadataservice/" + video.id()) .<VideoMetadata>flatMap(HttpClientResponse::getContent), (b, r, m) -> combineVideoData(video, b, r, m))) ))); Delivering Netflix! Disclaimer: This is an example and not an exact representation of the processing -
return HttpServer.newServer(port) .start((req, resp) -> catalogClient.createGet("http://catalogservice/catalog") .switchMap(catalogResp -> resp.sendHeaders() .write(catalogResp.flatMap(catalog
-> Catalog::videos) .flatMap(video -> Observable.zip(bookmarkClient.createGet("http://bookmarkservice/" + video.id()) .<Bookmark>flatMap(HttpClientResponse::getContent), ratingClient.createGet("http://ratingsservice/" + video.id()) .<Rating>flatMap(HttpClientResponse::getContent), metadataClient.createGet("http://metadataservice/" + video.id()) .<VideoMetadata>flatMap(HttpClientResponse::getContent), (b, r, m) -> combineVideoData(video, b, r, m))) ))); Delivering Netflix! Disclaimer: This is an example and not an exact representation of the processing -
return HttpServer.newServer(port) .start((req, resp) -> catalogClient.createGet("http://catalogservice/catalog") .switchMap(catalogResp -> resp.sendHeaders() .write(catalogResp.flatMap(catalog
-> Catalog::videos) .flatMap(video -> Observable.zip(bookmarkClient.createGet("http://bookmarkservice/" + video.id()) .<Bookmark>flatMap(HttpClientResponse::getContent), ratingClient.createGet("http://ratingsservice/" + video.id()) .<Rating>flatMap(HttpClientResponse::getContent), metadataClient.createGet("http://metadataservice/" + video.id()) .<VideoMetadata>flatMap(HttpClientResponse::getContent), (b, r, m) -> combineVideoData(video, b, r, m))) ))); Delivering Netflix! Disclaimer: This is an example and not an exact representation of the processing -
return HttpServer.newServer(port) .start((req, resp) -> catalogClient.createGet("http://catalogservice/catalog") .switchMap(catalogResp -> resp.sendHeaders() .write(catalogResp.flatMap(catalog
-> Catalog::videos) .flatMap(video -> Observable.zip(bookmarkClient.createGet("http://bookmarkservice/" + video.id()) .<Bookmark>flatMap(HttpClientResponse::getContent), ratingClient.createGet("http://ratingsservice/" + video.id()) .<Rating>flatMap(HttpClientResponse::getContent), metadataClient.createGet("http://metadataservice/" + video.id()) .<VideoMetadata>flatMap(HttpClientResponse::getContent), (b, r, m) -> combineVideoData(video, b, r, m))) ))); Delivering Netflix! Disclaimer: This is an example and not an exact representation of the processing -
return HttpServer.newServer(port) .start((req, resp) -> catalogClient.createGet("http://catalogservice/catalog") .switchMap(catalogResp -> resp.sendHeaders() .write(catalogResp.flatMap(catalog
-> Catalog::videos) .flatMap(video -> Observable.zip(bookmarkClient.createGet("http://bookmarkservice/" + video.id()) .<Bookmark>flatMap(HttpClientResponse::getContent), ratingClient.createGet("http://ratingsservice/" + video.id()) .<Rating>flatMap(HttpClientResponse::getContent), metadataClient.createGet("http://metadataservice/" + video.id()) .<VideoMetadata>flatMap(HttpClientResponse::getContent), (b, r, m) -> combineVideoData(video, b, r, m))) ))); Delivering Netflix! Disclaimer: This is an example and not an exact representation of the processing -
return HttpServer.newServer(port) .start((req, resp) -> catalogClient.createGet("http://catalogservice/catalog") .switchMap(catalogResp -> resp.sendHeaders() .write(catalogResp.flatMap(catalog
-> Catalog::videos) .flatMap(video -> Observable.zip(bookmarkClient.createGet("http://bookmarkservice/" + video.id()) .<Bookmark>flatMap(HttpClientResponse::getContent), ratingClient.createGet("http://ratingsservice/" + video.id()) .<Rating>flatMap(HttpClientResponse::getContent), metadataClient.createGet("http://metadataservice/" + video.id()) .<VideoMetadata>flatMap(HttpClientResponse::getContent), (b, r, m) -> combineVideoData(video, b, r, m))) ))); Delivering Netflix! Disclaimer: This is an example and not an exact representation of the processing -
return HttpServer.newServer(port) .start((req, resp) -> catalogClient.createGet("http://catalogservice/catalog") .switchMap(catalogResp -> resp.sendHeaders() .write(catalogResp.flatMap(catalog
-> Catalog::videos) .flatMap(video -> Observable.zip(bookmarkClient.createGet("http://bookmarkservice/" + video.id()) .<Bookmark>flatMap(HttpClientResponse::getContent), ratingClient.createGet("http://ratingsservice/" + video.id()) .<Rating>flatMap(HttpClientResponse::getContent), metadataClient.createGet("http://metadataservice/" + video.id()) .<VideoMetadata>flatMap(HttpClientResponse::getContent), (b, r, m) -> combineVideoData(video, b, r, m))) ))); Delivering Netflix! Disclaimer: This is an example and not an exact representation of the processing -
Delivering Netflix Edge Service Observable Personalized catalog Service Ratings Service
Video Metadata Service Observable Bookmarks Service Disclaimer: This is an example and not an exact representation of the processing Observable Observable Observable -
Client Server Unidirectional protocol (eg: HTTP/1) Observable Send response onNext
Close connection unsubscribe Write Request Subscribe -
Client Server Write Request Subscribe Send response onNext Bidirectional protocol
(eg: HTTP/2) Observable -
Client Server Send response onNext Send unsubscribe unsubscribe Write Request
Subscribe Bidirectional protocol (eg: HTTP/2) Observable -
Your Service Services as an Observable.* * Courtesy: “Your Server
as a function” - Marius Eriksen -
Your Services as an Observable.* * Courtesy: “Your Server as
a function” - Marius Eriksen Reactive IPC -
Thank you! RxJava: https://github.com/ReactiveX/RxJava Reactive IPC: https://github.com/ReactiveX/RxNetty Service Discovery: https://github.com/Netflix/eureka/tree/2.x
Load balancing: https://github.com/Netflix/ocelli Server as a function: http://monkey.org/~marius/funsrv.pdf Fallacies of distributed computing: en.wikipedia.org/wiki/ Fallacies_of_distributed_computing#The_fallacies Nitesh Kant @NiteshKant