SlideShare a Scribd company logo
Mirco Dotta
@mircodotta
Akka Streams
Asynchronous non-blocking streaming made easy
1
Reactive	
  Applications
The Four Reactive Traits
http://reactivemanifesto.org/
2
Why Reactive?
3
Why Reactive?
• Users expectations have changed
• Services must be always up.
• Must be fast.
• Billions of internet connected devices.
• Data is transformed and pushed continuously.
4
Reactive Streams
An initiative for providing
Standardised(!)
Back-pressured
Asynchronous
Stream processing
!
http://www.reactive-streams.org/
5
Reactive Streams: Who?
!
• Kaazing
• Netflix (rxJava)
• Pivotal (reactor)
• RedHat (vert.x)
• Twitter
• Typesafe (akka-streams & slick)
• Play 2.4 also supports reactive streams!
• Doug Lea proposed an implementation for JDK9!
!
!
6
Standardised!
7
Reactive Streams: Inter-op
!
We want to make different implementations
co-operate with each other.
8
Reactive Streams: Inter-op
The different implementations “talk to each other”
using the Reactive Streams protocol.
9
Reactive Streams: Inter-op
// here are a few imports that you are not seeing!
object ScalaMain extends App {!
EmbeddedApp.fromHandler(new Handler {!
override def handle(ctx: Context): Unit = {!
// RxJava Observable!
val intObs = Observable.from((1 to 10).asJava)!
! // Reactive Streams Publisher!
val intPub = RxReactiveStreams.toPublisher(intObs)!
! // Akka Streams Source!
val stringSource = Source(intPub).map(_.toString)!
! // Reactive Streams Publisher!
val stringPub = stringSource.runWith(Sink.fanoutPublisher(1, 1))!
! // Reactor Stream!
val linesStream = Streams.create(stringPub).map[String](new reactor.function.Function[String, String] {!
override def apply(in: String) = in + "n"!
})!
! // and now render the HTTP response (RatPack)!
ctx.render(ResponseChunks.stringChunks(linesStream))!
}!
! }).test(new Consumer[TestHttpClient] {!
override def accept(client: TestHttpClient): Unit = {!
val text = client.getText()!
println(text)!
system.shutdown()!
}!
})!
} https://github.com/rkuhn/ReactiveStreamsInterop
10
Reactive Streams: Inter-op
The Reactive Streams SPI is NOT meant to be user-
api. You should use one of the implementing
libraries.
11
Akka Streams
12
Akka Streams: Basics
• DSL for the formulation of transformations on
data streams.
• Basic building blocks:
• Source	
  -­‐	
  something with exactly one output stream.
• Flow - something with exactly one input and one output
stream.
• Sink - something with exactly one input stream.
• RunnableFlow - A Flow that has both ends “attached”
to a Source and Sink respectively, and is ready to be run() .
13
Akka Streams: Basics
14
Akka Streams: Basics
15
Akka Streams: Basics
16
Demo 1
17
Akka Streams: Graph
• Source, Flow, and	
  Sink	
  are good for expressing
linear computations.
• But how to express a computation graph?
18
Demo 2
19
Akka Streams: Fan-out
• Broadcast	
  -­‐	
   given an input element emits to each
output.
• Balance- given an input element emits to one of its
output ports.
• UnZip - splits a stream of (A,B) tuples into two
streams, one of type A and on of type B.
• FlexiRoute	
  -­‐ enables writing custom fan out
elements using a simple DSL.
20
Akka Streams: Fan-in
• Merge	
  -­‐	
   picks randomly from inputs pushing them one
by one to its output.
• MergePreferred	
  - like Merge but if elements are
available on preferred port, it picks from it, otherwise
randomly from others.
• 	
  ZipWith(fn)- takes a function of N inputs that
given a value for each input emits 1 output element.
21
Akka Streams: Fan-in cont’d
• Zip	
  - is a ZipWith specialised to zipping input streams
of A and B into an (A,B) tuple stream.
• Concat	
  - concatenates two streams (first consume
one, then the second one).
• FlexiMerge	
  - enables writing custom fan-in
elements using a simple DSL.
22
Demo 3
23
What is back-pressure?
24
Back-pressure? Example Without
Publisher[T] Subscriber[T]
25
Back-pressure? Example Without
Fast Publisher Slow Subscriber
26
Back-pressure?
“Why would I need that!?”
27
Back-pressure? Push + NACK model
28
Back-pressure? Push + NACK model
Subscriber usually has some kind of buffer.
29
Back-pressure? Push + NACK model
30
Back-pressure? Push + NACK model
31
Back-pressure? Push + NACK model
What if the buffer overflows?
32
Back-pressure? Push + NACK model (a)
Use bounded buffer,
drop messages + require re-sending
33
Back-pressure? Push + NACK model (a)
Kernel does this!	

Routers do this!	

(TCP)
Use bounded buffer,
drop messages + require re-sending
34
Back-pressure? Push + NACK model (b)
Increase buffer size…
Well, while you have memory available!
35
Back-pressure? Push + NACK model (b)
36
Negative ACKnowledgement
37
Back-pressure? Example NACKing
Buffer overflow is imminent!
38
Back-pressure? Example NACKing
Telling the Publisher to slow down / stop sending…
39
Back-pressure? Example NACKing
NACK did not make it in time,
because M was in-flight!
40
Back-pressure?
NACKing is NOT enough.
41
Back-pressure?
!
speed(publisher) < speed(subscriber)
42
Back-pressure? Fast Subscriber, No Problem
No problem!
43
Back-pressure?
Reactive-Streams
=
44
Just push – not safe when Slow Subscriber
!
!
Just pull – too slow when Fast Subscriber
Back-pressure? RS: Dynamic Push/Pull
45
!
!
!
Solution:
Dynamic adjustment
Back-pressure? RS: Dynamic Push/Pull
Just push – not safe when Slow Subscriber
!
!
Just pull – too slow when Fast Subscriber
46
Back-pressure? RS: Dynamic Push/Pull
Slow Subscriber sees it’s buffer can take 3 elements.
Publisher will never blow up it’s buffer.
47
Back-pressure? RS: Dynamic Push/Pull
Fast Publisher will send at-most 3 elements. This
is pull-based-backpressure.
48
Back-pressure? RS: Dynamic Push/Pull
Fast Subscriber can issue more Request(n),
before more data arrives!
49
Back-pressure? RS: Dynamic Push/Pull
Fast Subscriber can issue more Request(n),
before more data arrives.
!
Publisher can accumulate demand.
50
Back-pressure? RS: Accumulate demand
Publisher accumulates total demand per subscriber.
51
Back-pressure? RS: Accumulate demand
Total demand of elements is safe to publish.
Subscriber’s buffer will not overflow.
52
Demo 4
53
Is that really all there is to know?
• Naaaa, there is a lot more for you to explore!
• If the existing building blocks are not enough, define
your owns.
• Use mapAsync/mapAsyncUnordered for
integrating with external services.
• Streams Error Handling.
• Handling TCP connections with Streams.
• Integration with Actors.
54
What now?
• Use it:

"com.typesafe.akka" %% "akka-stream-experimental" % "1.0-RC2"
• Check out the Activator template

Akka Streams with Java8orScala.
• Akka Streams API doc and user guide for both
Java8 and Scala.
• Code used for the demos https://github.com/
dotta/akka-streams-demo/releases/tag/v02
55
Next Steps
• Akka Streams 1.0 final soon.
• Inclusion in future JDK (shooting for JDK9)
• We aim at polyglot standard (JS, wire proto)
• Try it out and give feedback!
• http://reactive-streams.org/
• https://github.com/reactive-streams
56
57
©Typesafe 2015 – All Rights Reserved
58

More Related Content

PDF
Akka streams
PDF
Akka Streams and HTTP
PDF
Reactive Stream Processing with Akka Streams
PDF
Reactive Streams / Akka Streams - GeeCON Prague 2014
ODP
Akka streams
PDF
Journey into Reactive Streams and Akka Streams
PDF
2014 akka-streams-tokyo-japanese
PPTX
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Akka streams
Akka Streams and HTTP
Reactive Stream Processing with Akka Streams
Reactive Streams / Akka Streams - GeeCON Prague 2014
Akka streams
Journey into Reactive Streams and Akka Streams
2014 akka-streams-tokyo-japanese
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...

What's hot (20)

PPTX
How to manage large amounts of data with akka streams
PDF
Reactive Streams 1.0 and Akka Streams
PDF
Asynchronous stream processing with Akka Streams
PPTX
Real-time streaming and data pipelines with Apache Kafka
PDF
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
PPTX
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Kafka
PPTX
Realtime Statistics based on Apache Storm and RocketMQ
PPTX
Service Stampede: Surviving a Thousand Services
PPTX
Asynchronous Orchestration DSL on squbs
PDF
Reactor, Reactive streams and MicroServices
PDF
VJUG24 - Reactive Integrations with Akka Streams
PDF
PSUG #52 Dataflow and simplified reactive programming with Akka-streams
PDF
Practical Akka HTTP - introduction
PDF
Scala usergroup stockholm - reactive integrations with akka streams
PDF
Streaming all the things with akka streams
PDF
Big data: Loading your data with flume and sqoop
PPT
Specs2 whirlwind tour at Scaladays 2014
PPT
Introduction to Spark Streaming
PDF
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
PPTX
Stream processing from single node to a cluster
How to manage large amounts of data with akka streams
Reactive Streams 1.0 and Akka Streams
Asynchronous stream processing with Akka Streams
Real-time streaming and data pipelines with Apache Kafka
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Kafka
Realtime Statistics based on Apache Storm and RocketMQ
Service Stampede: Surviving a Thousand Services
Asynchronous Orchestration DSL on squbs
Reactor, Reactive streams and MicroServices
VJUG24 - Reactive Integrations with Akka Streams
PSUG #52 Dataflow and simplified reactive programming with Akka-streams
Practical Akka HTTP - introduction
Scala usergroup stockholm - reactive integrations with akka streams
Streaming all the things with akka streams
Big data: Loading your data with flume and sqoop
Specs2 whirlwind tour at Scaladays 2014
Introduction to Spark Streaming
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Stream processing from single node to a cluster
Ad

Viewers also liked (20)

PDF
Distributed Systems Done Right: Why Java Enterprises Are Embracing The Actor ...
PDF
Akka Streams - From Zero to Kafka
PDF
Managing Binary Compatibility in Scala (Scala Days 2011)
PDF
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems (Soft-Sha...
PDF
Scala Past, Present & Future
PDF
Enterprise Development Trends 2016 - Cloud, Container and Microservices Insig...
PDF
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
PDF
Effective Scala (SoftShake 2013)
PDF
93-42-eec相关标准
PDF
Personality & the Brain: A new perspective on the INTP
PDF
3820 kh2 launch leaflet press v2
PPT
Email Management
PPTX
How to get published as a PhD student
DOCX
82339495 part-iv-all-vaccines-are-dangerous
PPTX
LEÇON 364 – Cet instant saint, je voudrais Te le donner.
PDF
Social Media for Architects
PPTX
Spaces and places - transforming the public library
PPTX
LEÇON 363 – Cet instant saint, je voudrais Te le donner.
PPTX
Social Media for Assisted Living: Best Friend or Worst Enemy?
Distributed Systems Done Right: Why Java Enterprises Are Embracing The Actor ...
Akka Streams - From Zero to Kafka
Managing Binary Compatibility in Scala (Scala Days 2011)
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems (Soft-Sha...
Scala Past, Present & Future
Enterprise Development Trends 2016 - Cloud, Container and Microservices Insig...
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
Effective Scala (SoftShake 2013)
93-42-eec相关标准
Personality & the Brain: A new perspective on the INTP
3820 kh2 launch leaflet press v2
Email Management
How to get published as a PhD student
82339495 part-iv-all-vaccines-are-dangerous
LEÇON 364 – Cet instant saint, je voudrais Te le donner.
Social Media for Architects
Spaces and places - transforming the public library
LEÇON 363 – Cet instant saint, je voudrais Te le donner.
Social Media for Assisted Living: Best Friend or Worst Enemy?
Ad

Similar to Akka streams scala italy2015 (20)

PDF
Mirco Dotta - Akka Streams
PDF
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
PDF
End to End Akka Streams / Reactive Streams - from Business to Socket
PDF
Reactive Streams: Handling Data-Flow the Reactive Way
PDF
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
PDF
Akka stream and Akka CQRS
PDF
Reactive Streams, j.u.concurrent & Beyond!
PDF
How Reactive Streams & Akka Streams change the JVM Ecosystem
PDF
Reactive Streams 1.0.0 and Why You Should Care (webinar)
PPTX
A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0
PDF
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
PPTX
Reactive Streams
PDF
Introduction to Akka Streams
PDF
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
PDF
Reactive integrations with Akka Streams
PDF
Reactive stream processing using Akka streams
PDF
Akka Streams in Action @ ScalaDays Berlin 2016
PDF
Reactive Streams, j.u.concurrent, & Beyond!
ODP
Introduction to Akka Streams [Part-I]
PPTX
Intro to Akka Streams
Mirco Dotta - Akka Streams
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
End to End Akka Streams / Reactive Streams - from Business to Socket
Reactive Streams: Handling Data-Flow the Reactive Way
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
Akka stream and Akka CQRS
Reactive Streams, j.u.concurrent & Beyond!
How Reactive Streams & Akka Streams change the JVM Ecosystem
Reactive Streams 1.0.0 and Why You Should Care (webinar)
A Deeper Look Into Reactive Streams with Akka Streams 1.0 and Slick 3.0
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Reactive Streams
Introduction to Akka Streams
Exploring Reactive Integrations With Akka Streams, Alpakka And Apache Kafka
Reactive integrations with Akka Streams
Reactive stream processing using Akka streams
Akka Streams in Action @ ScalaDays Berlin 2016
Reactive Streams, j.u.concurrent, & Beyond!
Introduction to Akka Streams [Part-I]
Intro to Akka Streams

Recently uploaded (20)

PPTX
Big Data Technologies - Introduction.pptx
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Machine learning based COVID-19 study performance prediction
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
Cloud computing and distributed systems.
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
Encapsulation theory and applications.pdf
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
Big Data Technologies - Introduction.pptx
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction
MYSQL Presentation for SQL database connectivity
Cloud computing and distributed systems.
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Advanced methodologies resolving dimensionality complications for autism neur...
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Encapsulation_ Review paper, used for researhc scholars
NewMind AI Monthly Chronicles - July 2025
Encapsulation theory and applications.pdf
NewMind AI Weekly Chronicles - August'25 Week I
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
The Rise and Fall of 3GPP – Time for a Sabbatical?
Reach Out and Touch Someone: Haptics and Empathic Computing

Akka streams scala italy2015