Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Embracing Streams - Everywhere

Nitesh Kant
October 10, 2016

Embracing Streams - Everywhere

“I don’t need stream processing because I don’t have streaming data.” - Anonymous

In general people relate to streams as data models which are naturally streaming (infinite asynchronous messages) or relate to realtime big data processing. In this talk Nitesh Kant, will try to break this myth by emphasizing the fact that streams exists everywhere, be it data read from sockets, protocols like HTTP or microservice composition. He will explain how extending this ubiquitous interaction model into applications can result in simpler, resilient and maintainable systems.
You will learn, how to start thinking “streaming first” through concrete examples and how adopting this mental model makes writing application easier.

Presented at ReactiveSummit2016: https://reactivesummit2016.sched.org/event/7geB/embracing-streamseverywhere

Video: https://www.youtube.com/watch?v=5FE6xnH5Lak

Nitesh Kant

October 10, 2016
Tweet

More Decks by Nitesh Kant

Other Decks in Technology

Transcript

  1. Nitesh Kant Who Am I? ❖ Engineer, Edge Engineering, Netflix.

    ❖ Core contributor, RxNetty* ❖ Contributor, ReactiveSocket** * https://github.com/ReactiveX/RxNetty ** https://github.com/ReactiveSocket @NiteshKant https://speakerdeck.com/niteshkant
  2. public Movie getMovie(String movieId) { Metadata metadata = getMovieMetadata(movieId); Bookmark

    bookmark = getBookmark(movieId, userId); Rating rating = getRatings(movieId); return new Movie(metadata, bookmark, rating); } Disclaimer: This is an example and not an exact representation of the processing
  3. In a microservices world Edge Service Ratings Service Video Metadata

    Service Bookmarks Service Disclaimer: This is an example and not an exact representation of the processing
  4. Edge Service Video Metadata Service Disclaimer: This is an example

    and not an exact representation of the processing GET /movie?id=3 HTTP/1.1
  5. Video Metadata Service Disclaimer: This is an example and not

    an exact representation of the processing GET /movie?id=3 HTTP/1.1 HTTP/1.1 200 OK Edge Service
  6. Video Metadata Service Disclaimer: This is an example and not

    an exact representation of the processing GET /movie?id=3 HTTP/1.1 HTTP/1.1 200 OK Edge Service
  7. Disclaimer: This is an example and not an exact representation

    of the processing GET /movie?id=3 HTTP/1.1 HTTP/1.1 200 OK Edge Service
  8. Disclaimer: This is an example and not an exact representation

    of the processing GET /movie?id=3 HTTP/1.1 HTTP/1.1 200 OK Edge Service Meanwhile
  9. Disclaimer: This is an example and not an exact representation

    of the processing GET /movie?id=3 HTTP/1.1 HTTP/1.1 200 OK Edge Service Request pileup
  10. Disclaimer: This is an example and not an exact representation

    of the processing public Movie getMovie(String movieId) { Metadata metadata = getMovieMetadata(movieId); Bookmark bookmark = getBookmark(movieId, userId); Rating rating = getRatings(movieId); return new Movie(metadata, bookmark, rating); } Edge Service
  11. One-way street No way to provide feedback. Disclaimer: This is

    an example and not an exact representation of the processing public Movie getMovie(String movieId) { Metadata metadata = getMovieMetadata(movieId); Bookmark bookmark = getBookmark(movieId, userId); Rating rating = getRatings(movieId); return new Movie(metadata, bookmark, rating); }
  12. Subscriber Sink for the stream. public interface Subscriber<T> { public

    void onSubscribe(Subscription s); public void onNext(T t); public void onError(Throwable t); public void onComplete(); }
  13. public interface Subscriber<T> { public void onSubscribe(Subscription s); public void

    onNext(T t); public void onError(Throwable t); public void onComplete(); } Zero or more items.
  14. public interface Subscriber<T> { public void onSubscribe(Subscription s); public void

    onNext(T t); public void onError(Throwable t); public void onComplete(); } At most one terminal event.
  15. public interface Subscriber<T> { public void onSubscribe(Subscription s); public void

    onNext(T t); public void onError(Throwable t); public void onComplete(); } Publisher supplied control handle.
  16. Request Processing Edge Service Video Metadata Service Disclaimer: This is

    an example and not an exact representation of the processing Bookmarks Service Ratings Service
  17. Edge Service Video Metadata Service Disclaimer: This is an example

    and not an exact representation of the processing Rating service C* store C* store /movie?id=123
  18. Network Protocol Application Level Flow Control Cancellation Item Emissions (onNext)

    Terminal Events (onError/Complete) }Consumer => Producer
  19. Network Protocol Application Level Flow Control Cancellation Item Emissions (onNext)

    Terminal Events (onError/Complete) { Producer => Consumer
  20. HTTP/1.1 GET /movie?id=3 HTTP/1.1 GET /movie?id=2 HTTP/1.1 GET /movie?id=1 HTTP/1.1

    HTTP/1.1 200 OK ID: 1 … HTTP/1.1 200 OK ID: 2 … HTTP/1.1 200 OK ID: 3 …
  21. HTTP/1.1 GET /movie?id=3 HTTP/1.1 GET /movie?id=2 HTTP/1.1 GET /movie?id=1 HTTP/1.1

    HTTP/1.1 200 OK ID: 1 … HTTP/1.1 200 OK ID: 2 … HTTP/1.1 200 OK ID: 3 … Uni-directional
  22. Common entity Flow controlled stream User (device) controlled stream is

    a natural way to paginate, hence, reducing network data transfer.
  23. curl -v "http://www.netflix.com"\ > GET / HTTP/1.1\ > \ <

    HTTP/1.1 302 Found\ < Date: Tue, 04 Oct 2016 02:37:51 GMT\ < set-cookie: nflx-rgn=uw2| 1475548671570; Max-Age=-1; Expires=Tue, 04 Oct 2016 02:37:50 GMT; Path=/; Domain=.netflix.com\ < Connection: keep-alive\ < \
  24. Edge Service Video Metadata Service Rating service C* store C*

    store /movie?id=123 Disclaimer: This is an example and not an exact representation of the processing
  25. Edge Service Video Metadata Service Rating service C* store C*

    store /movie?id=123 X Disclaimer: This is an example and not an exact representation of the processing
  26. Edge Service Video Metadata Service Rating service C* store C*

    store /movie?id=123 X X X X X Disclaimer: This is an example and not an exact representation of the processing
  27. Typical throttling Video Metadata Service Disclaimer: This is an example

    and not an exact representation of the processing GET /movie?id=3 HTTP/1.1 HTTP/1.1 200 OK Edge Service
  28. Typical throttling Disclaimer: This is an example and not an

    exact representation of the processing GET /movie?id=3 HTTP/1.1 HTTP/1.1 200 OK Edge Service HTTP/1.1 503 Service Unavailable
  29. Typical throttling Disclaimer: This is an example and not an

    exact representation of the processing GET /movie?id=3 HTTP/1.1 HTTP/1.1 200 OK Edge Service HTTP/1.1 503 Service Unavailable Backoff
  30. Typical throttling Disclaimer: This is an example and not an

    exact representation of the processing GET /movie?id=3 HTTP/1.1 HTTP/1.1 200 OK Edge Service HTTP/1.1 503 Service Unavailable Backoff When will this server be ok?
  31. Eliminating guesswork? Disclaimer: This is an example and not an

    exact representation of the processing GET /movie?id=3 HTTP/1.1 HTTP/1.1 200 OK Edge Service HTTP/1.1 503 Service Unavailable Backoff When will this server be ok?
  32. Request-leasing Peer 1 Peer 2 “Lease” 5 requests for 1

    second. GET /movie?id=1 HTTP/1.1 GET /movie?id=2 HTTP/1.1 Network connection
  33. Server Capacity: 100 RPS Client 1 Client 2 Client 8

    “Lease” 10 requests for 1 second.
  34. Server Capacity: 100 RPS Client 1 Client 2 Client 8

    “Lease” 10 requests for 1 second. “Lease” 10 requests for 1 second. “Lease” 10 requests for 1 second.
  35. Server Capacity: 100 RPS Client 1 Client 2 Client 8

    “Lease” 10 requests for 1 second. “Lease” 10 requests for 1 second. “Lease” 10 requests for 1 second. Reserve Capacity: 20 RPS
  36. Time bound lease. No extra work for cancelling leases. Receiver

    controls the flow of requests “Lease” 10 requests for 1 second.
  37. Server Capacity: 20 RPS Client 1 Client 2 Client 8

    “Lease” 5 requests for 1 second. “Lease” 2 requests for 1 second. X No more “Lease”
  38. Server Capacity: 20 RPS Client 1 Client 2 Client 8

    “Lease” 5 requests for 1 second. “Lease” 2 requests for 1 second. X No more “Lease” Prioritization
  39. Server Capacity: 100 RPS Client 1 Client 2 Client 8

    “Lease” 10 requests for 1 second. “Lease” 10 requests for 1 second. “Lease” 10 requests for 1 second. Reserve Capacity: 20 RPS
  40. Server Capacity: 100 RPS Client 1 Client 2 Client 8

    “Lease” 10 requests for 1 second. “Lease” 10 requests for 1 second. “Lease” 10 requests for 1 second. Reserve Capacity: 20 RPS Self Healing!
  41. Edge Service Video Metadata Service Rating service C* store C*

    store Disclaimer: This is an example and not an exact representation of the processing /movie?id=123
  42. Edge Service Video Metadata Service Rating service C* store C*

    store Disclaimer: This is an example and not an exact representation of the processing /movie?id=123 Publisher<Movie>
  43. public interface Publisher<T> { public void subscribe(Subscriber<? super T> s);

    } public interface Subscriber<T> { public void onSubscribe(Subscription s); public void onNext(T t); public void onError(Throwable t); public void onComplete(); } public interface Subscription { public void request(long n); public void cancel(); } Stream s