Slide 1

Slide 1 text

Reactive Streams The Glue of the Real-time Organization

Slide 2

Slide 2 text

What to expect » Introduction » A Journey into Reactive Streams » Diving into Akka Streams » Code walkthrough and demo » Q&A

Slide 3

Slide 3 text

“If analytics are the brain of an organization, streams are the heart.”

Slide 4

Slide 4 text

An Introduction

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Appeal of streams? » Per-event processing (≤ 1 second latencies) » Mini-batch processing (≤ 10 second latencies) » Batch processing (≤ 1 hour latencies) » Monitoring, analytics, complex event processing

Slide 8

Slide 8 text

Challenges? » Ephemeral » Unbounded in size » Potential flooding » Unfamiliar

Slide 9

Slide 9 text

Reactive Streams

Slide 10

Slide 10 text

Reactive Streams? » Reactive Streams is a specification and low-level API for library developers

Slide 11

Slide 11 text

Reactive Streams? » Reactive Streams is a specification and low-level API for library developers » Started as an initiative in late 2013 between engineers at Netflix, Pivotal, and Lightbend

Slide 12

Slide 12 text

Reactive Streams? » Reactive Streams is a specification and low-level API for library developers » Started as an initiative in late 2013 between engineers at Netflix, Pivotal, and Lightbend » Aimed to address two critical challenges » Interoperability between streaming libraries » Flow control over an asynchronous boundary

Slide 13

Slide 13 text

What is Reactive Streams? » TCK (Technology Compatibility Kit) » API (JVM, JavaScript) » Specifications for library developers

Slide 14

Slide 14 text

Flow control

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

No content

Slide 18

Slide 18 text

No content

Slide 19

Slide 19 text

No content

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

Interop » RxJava (Netflix) » Reactor (Pivotal) » Vert.x (RedHat) » Akka Streams (Lightbend) » Slick (Lightbend)

Slide 24

Slide 24 text

Reactive Streams Visit the Reactive Streams website for more information. http://www.reactive-streams.org/

Slide 25

Slide 25 text

Akka Streams

Slide 26

Slide 26 text

Akka Streams » A library to express and run a chain of asynchronous processing steps acting on a sequence of elements » DSL for async/non-blocking stream processing » Backpressure enabled by default » Implements the Reactive Streams spec for interoperability » Scala and Java APIs

Slide 27

Slide 27 text

Asynchronous boundary

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

Basics

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

No content

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

No content

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

Let's analyze flight data 1.Read in all flight data from 2008 2.Transform CSV rows to data structures 3.Compute the average delay per airline 4.Emit the results to console

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

val g: RunnableGraph[_] = RunnableGraph.fromGraph(GraphDSL.create() { implicit builder => // Source val A: Outlet[String] = builder.add(Source.fromIterator(() => flightDelayLines)).out val B: FlowShape[String, FlightEvent] = builder.add(csvToFlightEvent) val C: Inlet[Any] = builder.add(Sink.ignore).in import GraphDSL.Implicits._ // allows us to build our graph using ~> combinators // Graph A ~> B ~> C ClosedShape // defines this as a "closed" graph, not exposing any inlets or outlets }) g.run() // materializes and executes the blueprint

Slide 45

Slide 45 text

API design Considerations » Immutable, composable stream blueprints » Explicit materialization step » No magic at the expense of some extra code

Slide 46

Slide 46 text

Materialization Separates the what from the how. » Use Source/Flow/Sink to create a blueprint » FlowMaterializer turns a blueprint into Akka Actors

Slide 47

Slide 47 text

Graphs

Slide 48

Slide 48 text

No content

Slide 49

Slide 49 text

No content

Slide 50

Slide 50 text

No content

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Advanced flow control

Slide 53

Slide 53 text

No content

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

No content

Slide 56

Slide 56 text

No content

Slide 57

Slide 57 text

No content

Slide 58

Slide 58 text

No content

Slide 59

Slide 59 text

Code and review

Slide 60

Slide 60 text

No content

Slide 61

Slide 61 text

val g = RunnableGraph.fromGraph(GraphDSL.create() { implicit builder => import GraphDSL.Implicits._ // Source val A: Outlet[String] = builder.add(Source.fromIterator(() => flightDelayLines)).out // Flows val B: FlowShape[String, FlightEvent] = builder.add(csvToFlightEvent) val C: FlowShape[FlightEvent, FlightDelayRecord] = builder.add(filterAndConvert) val D: UniformFanOutShape[FlightDelayRecord, FlightDelayRecord] = builder.add(Broadcast[FlightDelayRecord](2)) val F: FlowShape[FlightDelayRecord, (String, Int, Int)] = builder.add(averageCarrierDelay) // Sinks val E: Inlet[Any] = builder.add(Sink.ignore).in val G: Inlet[Any] = builder.add(Sink.foreach(averageSink)).in // Graph A ~> B ~> C ~> D E <~ D G <~ F <~ D ClosedShape }) g.run()

Slide 62

Slide 62 text

No content

Slide 63

Slide 63 text

Thank you! Visit https://www.lightbend.com/products/lightbend- reactive-platform to get started Contact info » Lightbend: https://www.lightbend.com/contact » Twitter: @kvnwbbr » Email: [email protected]