Introduction to
Akka Streams
Presented By: Manish Mishra
Module Lead Software Consultant
Knoldus Inc.
LEARN NOW
About Knoldus
Knoldus is a technology consulting firm with focus on modernizing the digital systems
at the pace your business demands.
DevOps
Functional. Reactive. Cloud Native
01 What is Stream Processing
02 Reactive Streams
03 The Akka Streams Library
04 The Terminologies
05 Demo
Our Agenda
Stream Processing is handling live data
which is Produced at a point and after
some processing Consumed by Another
End
c
What is Stream
Processing ?
c
Stream Processing is handling live data
which is Produced at a point and after
some processing Consumed by Another
End
What is Stream
Processing ?
Producer
Stream Processing is handling live data
which is Produced at a point and after
some processing Consumed by Another
End
Producer Consumer
c
What is Stream
Processing ?
Stream Processing is handling live data
which is Produced at a point and after
some processing Consumed by Another
End
Producer Processing Consumer
c
What is Stream
Processing ?
c
But is it that
Simple?
Producer Processing Consumer
Producer Speed:
N Rec/Sec
Processing Speed:
n/2 Rec/Sec
Stream Processing: Technical Challenges
Producer Processing Consumer
Producer Speed:
N Rec/Sec
Processing Speed:
n/2 Rec/Sec
Stream Processing: Technical Challenges
Producer Processing Consumer
Producer Speed:
N Rec/Sec
Processing Speed:
n/2 Rec/Sec
After 2 Seconds
n Records in Buffer
Stream Processing: Technical Challenges
Producer Processing Consumer
Producer Speed:
N Rec/Sec
Processing Speed:
n/2 Rec/Sec
Consumer
Speed: N -5
Rec/Sec
After 10 Seconds
n*5 Records in Buffer
Stream Processing: Technical Challenges
Producer Processing Consumer
Producer Speed:
N Rec/Sec
Processing Speed:
n/2 Rec/Sec
Consumer
Speed: N -5
Rec/Sec
After some more
time Buffer is Full / OOM
Stream Processing: Technical Challenges
Producer Processing Consumer
Producer Speed:
N Rec/Sec
Processing Speed:
n/2 Rec/Sec
How To Tackle?
Stream Processing: Technical Challenges
c
Enter
Reactive Streams
c
But first, What is Reactive?
c
Reactive Streams is an initiative to
provide a standard for asynchronous
stream processing with non-blocking
back pressure.
https://www.reactive-streams.org/
What are Reactive
Streams ?
c
Reactive Streams is an initiative to
provide a standard for asynchronous
stream processing with non-blocking
back pressure.
https://www.reactive-streams.org/
What are Reactive
Streams ?
● It is an Interface.
● The interfaces available in JDK9’s
java.util.concurrent.Flow
The API consists of the following components
that are required to be provided by Reactive
Stream implementations:
1. Publisher
2. Subscriber
3. Subscription
4. Processor
What is Back Pressure ?
c
What is Back
Pressure ?
Back-pressure is an important
feedback mechanism that allows
systems to gracefully respond to load
rather than collapse under it.
https://www.reactive-streams.org/
c
Stream Processing: Technical Challenges
Producer Processing Consumer
Producer Speed:
N Rec/Sec
Processing Speed:
n/2 Rec/Sec
Consumer
Speed: N -5
Rec/Sec
After some more
time Buffer is Full
Producer Processing ConsumerProcessing
What is Back Pressure ?
Producer Processing Consumer
n records at the moment
please
Processing
What is Back Pressure ?
Producer Processing Consumer
n records at the moment
please
Processing
What is Back Pressure ?
Producer Processing Consumer
n records at the moment
please
Processing
n records at the moment
please
What is Back Pressure ?
c
Akka Streams Library
● A Library on the top of Akka Actors
● DSL for transformation on Data Streams
● Helps to create Reusable components
● Decoupled from the Reactive Streams Interface
Akka Streams Vs Reactive Streams Interface
The Akka Streams API is completely
decoupled from the Reactive Streams
interfaces. While Akka Streams focus on
the formulation of transformations on
data streams, the scope of Reactive
Streams is to define a common
mechanism of how to move data across
an asynchronous boundary without
losses, buffering or resource exhaustion.
-- Akka Stream DocsLEARN NO
c
How Reactive Streams Handles
back-pressure
Slow Publisher, fast Subscriber
● Happy Situation!! No Problem!!
● Resource underutilized?
● Signal Publisher to Publish at a higher rate.
● Never publish more than demanded to avoid the bottleneck.
c
How Reactive Streams Handles
back-pressure
Fast Publisher, slow Subscriber
● not generate elements, if it is able to control their production rate,
● try buffering the elements in a bounded manner until more demand is
signalled,
● drop elements until more demand is signalled,
● tear down the stream if unable to apply any of the above strategies.
c
How Akka Streams Handles
back-pressure
● Akka Streams implement an asynchronous non-blocking back-pressure
protocol standardised by the Reactive Streams specification
● The user of the library does not have to write any explicit back-pressure
handling code — it is built in and dealt with automatically by all of the
provided Akka Streams processing stages.
● The Publisher is implemented as Source and it is guaranteed that the data
can’t be generated more than the demand of the Subsriber.
c
Producer Processing Consumer
Source
Akka Stream Terminologies
c
Producer Processing Consumer
Source
Sink
Akka Stream Terminologies
c
Producer Processing Consumer
Source Sink
Flow
Akka Stream Terminologies
c
Producer Processing Consumer
Source Sink
Flow
The Asynch
Boundaries
Akka Stream Terminologies
c
Akka Stream: A Quick Example
Source[Int, NotUsed]
Akka Stream:
A Quick Example
c
Source[Int, NotUsed]
ActorMaterializer
Akka Stream:
A Quick Example
c
Source[Int, NotUsed]
ActorMaterializer
Processing +
Consumer
c
Akka Stream:
A Quick Example
c
Akka Stream:
A Quick Example
c
References:
● https://doc.akka.io/docs
● https://www.slideshare.net/johanandren/reactive-str
eam-processing-using-akka-streams
Thank You!
@manish_mishra
manish@knoldus.com

Introduction to Akka Streams