Reactive Streams

The Now

ScalaDays    2015-06-10@Amsterdam

Mathias Doenitz   / /

This presentation: http://spray.io/scaladays/2015/

Stream-based logic is all the rage

Streaming Rage Streaming Rage Streaming Rage Streaming Rage Streaming Rage Streaming Rage Streaming Rage Streaming Rage Streaming Rage Streaming Rage Streaming Rage Streaming Rage Streaming Rage Streaming Rage Streaming Rage Streaming Rage Streaming Rage Streaming Rage Streaming Rage

Why stream-based programming is cool

A simple processing graph
  • Intuitive, expressive and type-safe
  • Scales well across levels of abstraction
  • Well suited for today's (and tomorrow's) hardware

“Reactive Streams are the
hottest kid on the block”

Someone on the Internet

What Reactive Streams (RS) are

First and foremost:

Protocol for efficiently passing data
between two independent units of execution
in an async, non-blocking & bounded fashion

RS defuse async boundaries

Async Boundary Async Boundary Async Boundary Async Boundary Async Boundary Async Boundary

Reactive Streams are contagious

Contagiousness Contagiousness Contagiousness Contagiousness Contagiousness Contagiousness

RS can scale across the full stack

RS Stack RS Stack RS Stack RS Stack RS Stack

RS are more than a protocol

  • Java interface definitions (i.e. a JAR to depend on)
  • Growing number of implementations
  • TCK (Technology Compatibility Kit)
  • Nascent sub projects (net, io, js, ...)
  • Public Domain (CC0) License

Reactive Stream Java API


public interface Publisher<T> {
  public void subscribe(Subscriber<? super T> s);
}

public interface Subscription {
  public void request(long n);
  public void cancel();
}

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

Not for user consumption!
(Use RS Impl Library instead)

RS Impl Landscape as of v1.0.0

Implementation Landscape Implementation Landscape Implementation Landscape

Simple example: Monte Carlo Pie

Monte Carclo Pi(e)

"Complexified" example stream graph

Monte Carclo Pi(e)

Akka Stream Implementation

[DEMO]

Akka Stream

  • Built from scratch on Reactive Streams Protocol
  • Java and Scala user APIs
  • "Blueprint"-style abstractions (Sources, Flows, Sinks)
  • Supports fully general stream-graphs
  • Number of pre-defined transformations still somewhat small
  • Not very optimized yet, still marked "experimental"

RxScala Implementation

[DEMO]

Reactive Extensions

  • Mostly driven by Netflix Engineers
  • Broke the ground for Reactive Streams
  • Oldest, most known, most mature
  • Support for many different languages
  • Doesn't directly support RS yet,
    currently still needs adapter lib
  • Backpressure not fully supported yet,
    will do so in version 2.0

Reactor Implementation

[DEMO]

Reactor

  • RS implementation built from scratch
  • Java only
  • Internally based a lot on Disruptor
  • Focus: Performance
  • Current version (2.0.3) not very mature yet
  • Driven by Engineers from Pivotal

Roadmap

  • RS Protocol and API V 1.0 done
  • Evolve and tune existing implementations
  • More infrastructure implementations!
  • More domain adapters!
  • Expand off the JVM (e.g. JavaScript)
  • Explore sub-standards (TCP, IO, ...)

Resources

THANK YOU!

Q & A