Reactive Streams
Non-blocking asynchronous stream
processing with back-pressure
Jordan Parmer
@profparmer
What’s Reactive
Streaming?
2
“Common
mechanism to move
data across an
asynchronous
boundary without
losses, buffering, or
resource
exhaustion3
Common Use Cases
▪ Data pipeline processing
▫ Unbounded data volume
▪ Message queue streaming
▪ Network streaming
▪ File streaming
4
Reactive
Programming vs
Reactive Systems
5
Reactive Systems
6 reactivemanifesto.org
Reactive Programming Reactive
Systems
▪ Application-view
▪ CPU’s, threads, local
resources
▪ Per-process execution
▪ Event-driven
▪ Systems-view
▪ Process interaction
▪ Cohesion of parts
▪ Message-driven
7 https://www.oreilly.com/ideas/reactive-programming-vs-reactive-systems
Reactive Programming Reactive
Systems
▪ Application-view
▪ CPU’s, threads, local
resources
▪ Per-process execution
▪ Event-driven
▪ Systems-view
▪ Process interaction
▪ Cohesion of parts
▪ Message-driven
8 https://www.oreilly.com/ideas/reactive-programming-vs-reactive-systems
We are
talking about
this
How We Use It
9
Oseberg Use Case
10
Kafka KafkaMicro-Service
Messages Messages
Oseberg Use Case
11
Kafka KafkaMicro-Service
Messages Messages
Source SinkTransformations
Reactive Programming Workflow
Oseberg Use Case
12
Kafka Svc Kafka
Svc
Svc
SvcKafka
DB DB
Each service internally uses Reactive Streams API to
read from Kafka, transform messages, write to storage
(if necessary), and write to Kafka.
Akka Streams
API
13
General Workflow
14
Source or
Publisher
Sink or
Subscriber
General Workflow
15
Source or
Publisher
Sink or
Subscriber
Connected to
collection, stream,
iterator, etc.
Lazily emits records on
demand
Subscribes to upstream
flow and gathers
records
Produces demand
Series of chained operations
applied to records
Push-Based Systems Without
Back-Pressure
16
Fast
Publisher
Slow
Subscriber
Push records downstream
1000 ops/second 10 ops/second
Push-Based Systems Without
Back-Pressure
17
Fast
Publisher
Slow
Subscriber
● Must manually buffer and/or throttle
● Out-of-Memory risk
1000 ops/second 10 ops/second
Push records downstream
Push-Based Systems
Without Back-Pressure
18
Fast
Publisher
Slow
Subscriber
100 ops/second 1 op/second
Flow of pushed records
What if buffer
overflows?
https://www.lightbend.com/blog/understanding-akka-streams-back-pressure-and-asynchronous-architectures
Push-Based Systems
Without Back-Pressure
19
Fast
Publisher
Slow
Subscriber
100 ops/second 1 op/second
Flow of pushed records
Drop
messages and
re-send?
https://www.lightbend.com/blog/understanding-akka-streams-back-pressure-and-asynchronous-architectures
Push-Based Systems
Without Back-Pressure
20
Fast
Publisher
Slow
Subscriber
100 ops/second 1 op/second
Flow of pushed records
Extend buffer
size?
https://www.lightbend.com/blog/understanding-akka-streams-back-pressure-and-asynchronous-architectures
Push-Based Systems
Without Back-Pressure
21
Fast
Publisher
Slow
Subscriber
100 ops/second 1 op/second
Flow of pushed records
Extend buffer
size?
https://www.lightbend.com/blog/understanding-akka-streams-back-pressure-and-asynchronous-architectures
OOM
PENDING!!!
Reactive With Back-Pressure
22
Fast
Publisher
Slow
Subscriber
Pull-based on demand
If possible, publisher only emits on pull
Reactive With Back-Pressure
23
Fast
Publisher
Slow
Subscriber
Pull-based on demand
If possible, publisher only emits on pull
Request/signal for more records (aka demand)
Reactive With Back-Pressure
24
Fast
Publisher
Slow
Subscriber
Pull-based on demand
If possible, publisher only emits on pull
Request/signal for more records (aka demand)
Respond with more records
Reactive With Back-Pressure
25
Fast
Publisher
Slow
Subscriber
Request/signal for 2 more records
Respond up to 2 more records
Demand
Example
26
Composability
27 Images from http://doc.akka.io/docs/akka/current/scala/stream/stream-composition.html
Composability
28 Images from http://doc.akka.io/docs/akka/current/scala/stream/stream-composition.html
Composability
29 Images from http://doc.akka.io/docs/akka/current/scala/stream/stream-composition.html
Example
30
Asynchronous Boundaries
31
Source SinkFlow Flow Flow
Async Boundaries
Asynchronous Boundaries
32
Source SinkFlow Flow Flow
Async Boundaries
Actor Actor Actor
Example
33
Enterprise
Integrations
34
Alpakka
Enterprise Integration
https://github.com/akka/alpakka
Akka Streams
Kafka
Reactive Kafka API
Example
37
Questions?
Twitter @profparmer
38 Slide Design by Slides Carnival
Creative Commons Attribution License

Reactive Streams

Editor's Notes

  • #2 How many of you have used Reactive Streams? How many of you work with data processing? ETL? Big data techniques? Network communication?
  • #4 What are some techniques or challenges streaming data today? Requires lots of boiler-plate Tricky to manage system resources What happens when the stream is interrupted or fails on delivery?