SlideShare a Scribd company logo
Mirco Dotta
@mircodotta
Akka Streams
Asynchronous non-blocking streaming made easy
Cascata	
  Piumogna	
  a	
  Faido
Reactive	
  Applications
The Four Reactive Traits
http://reactivemanifesto.org/
Why Reactive?
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.
Reactive Streams
An initiative for providing
Standardised(!)
Back-pressured
Asynchronous
Stream processing
!
http://www.reactive-streams.org/
Reactive Streams: Who?
!
• Kaazing
• Netflix (rxJava)
• Pivotal (reactor)
• RedHat (vert.x)
• Twitter
• Typesafe (akka-streams & slick)
• Doug Lea proposed an implementation for JDK9!
!
!
Standardised!
Reactive Streams: Inter-op
!
We want to make different implementations
co-operate with each other.
Reactive Streams: Inter-op
The different implementations “talk to each other”
using the Reactive Streams protocol.
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
Reactive Streams: Inter-op
The Reactive Streams SPI is NOT meant to be user-
api. You should use one of the implementing
libraries.
Akka Streams
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() .
Akka Streams: Basics
Akka Streams: Basics
Akka Streams: Basics
Demo 1
Akka Streams: Graph
• Source, Flow, and	
  Sink	
  are good for expressing
linear computations.
• But how to express a computation graph?
Demo 2
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.
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.
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.
Demo 3
What is back-pressure?
Back-pressure? Example Without
Publisher[T] Subscriber[T]
Back-pressure? Example Without
Fast Publisher Slow Subscriber
Back-pressure?
“Why would I need that!?”
Back-pressure? Push + NACK model
Back-pressure? Push + NACK model
Subscriber usually has some kind of buffer.
Back-pressure? Push + NACK model
Back-pressure? Push + NACK model
Back-pressure? Push + NACK model
What if the buffer overflows?
Back-pressure? Push + NACK model (a)
Use bounded buffer,
drop messages + require re-sending
Back-pressure? Push + NACK model (a)
Kernel does this!	

Routers do this!	

(TCP)
Use bounded buffer,
drop messages + require re-sending
Back-pressure? Push + NACK model (b)
Increase buffer size…
Well, while you have memory available!
Back-pressure? Push + NACK model (b)
Negative ACKnowledgement
Back-pressure? Example NACKing
Buffer overflow is imminent!
Back-pressure? Example NACKing
Telling the Publisher to slow down / stop sending…
Back-pressure? Example NACKing
NACK did not make it in time,
because M was in-flight!
Back-pressure?
NACKing is NOT enough.
Back-pressure?
!
speed(publisher) < speed(subscriber)
Back-pressure? Fast Subscriber, No Problem
No problem!
Back-pressure?
Reactive-Streams
=
Just push – not safe when Slow Subscriber
!
!
Just pull – too slow when Fast Subscriber
Back-pressure? RS: Dynamic Push/Pull
!
!
!
Solution:
Dynamic adjustment
Back-pressure? RS: Dynamic Push/Pull
Just push – not safe when Slow Subscriber
!
!
Just pull – too slow when Fast Subscriber
Back-pressure? RS: Dynamic Push/Pull
Slow Subscriber sees it’s buffer can take 3 elements.
Publisher will never blow up it’s buffer.
Back-pressure? RS: Dynamic Push/Pull
Fast Publisher will send at-most 3 elements. This
is pull-based-backpressure.
Back-pressure? RS: Dynamic Push/Pull
Fast Subscriber can issue more Request(n),
before more data arrives!
Back-pressure? RS: Dynamic Push/Pull
Fast Subscriber can issue more Request(n),
before more data arrives.
!
Publisher can accumulate demand.
Back-pressure? RS: Accumulate demand
Publisher accumulates total demand per subscriber.
Back-pressure? RS: Accumulate demand
Total demand of elements is safe to publish.
Subscriber’s buffer will not overflow.
Demo 4
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.
What now?
• Use it:

"com.typesafe.akka" %% "akka-stream-experimental" % "1.0-M5"
• 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/v01
Next Steps
• Akka Streams RC1 soon (before end of April).
• 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
Akka streams
©Typesafe 2015 – All Rights Reserved

More Related Content

ODP
Akka streams
PDF
Akka streams scala italy2015
PDF
Akka Streams and HTTP
PDF
Journey into Reactive Streams and Akka Streams
PDF
Reactive Stream Processing with Akka Streams
PPTX
How to manage large amounts of data with akka streams
PPTX
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
PDF
Asynchronous stream processing with Akka Streams
Akka streams
Akka streams scala italy2015
Akka Streams and HTTP
Journey into Reactive Streams and Akka Streams
Reactive Stream Processing with Akka Streams
How to manage large amounts of data with akka streams
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Ka...
Asynchronous stream processing with Akka Streams

What's hot (20)

PDF
Reactive Streams / Akka Streams - GeeCON Prague 2014
PDF
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
PDF
Reactive Streams 1.0 and Akka Streams
PDF
2014 akka-streams-tokyo-japanese
PPTX
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Kafka
PDF
Scala usergroup stockholm - reactive integrations with akka streams
PPTX
Asynchronous Orchestration DSL on squbs
PPTX
Real-time streaming and data pipelines with Apache Kafka
PDF
VJUG24 - Reactive Integrations with Akka Streams
PDF
Streaming all the things with akka streams
PPTX
Service Stampede: Surviving a Thousand Services
PPT
Specs2 whirlwind tour at Scaladays 2014
PDF
PSUG #52 Dataflow and simplified reactive programming with Akka-streams
PDF
Akka Streams
PDF
Reactive Streams: Handling Data-Flow the Reactive Way
PDF
Practical Akka HTTP - introduction
PDF
Developing Secure Scala Applications With Fortify For Scala
PDF
Revitalizing Enterprise Integration with Reactive Streams
PPTX
Stream processing from single node to a cluster
PDF
A dive into akka streams: from the basics to a real-world scenario
Reactive Streams / Akka Streams - GeeCON Prague 2014
Build Real-Time Streaming ETL Pipelines With Akka Streams, Alpakka And Apache...
Reactive Streams 1.0 and Akka Streams
2014 akka-streams-tokyo-japanese
Back-Pressure in Action: Handling High-Burst Workloads with Akka Streams & Kafka
Scala usergroup stockholm - reactive integrations with akka streams
Asynchronous Orchestration DSL on squbs
Real-time streaming and data pipelines with Apache Kafka
VJUG24 - Reactive Integrations with Akka Streams
Streaming all the things with akka streams
Service Stampede: Surviving a Thousand Services
Specs2 whirlwind tour at Scaladays 2014
PSUG #52 Dataflow and simplified reactive programming with Akka-streams
Akka Streams
Reactive Streams: Handling Data-Flow the Reactive Way
Practical Akka HTTP - introduction
Developing Secure Scala Applications With Fortify For Scala
Revitalizing Enterprise Integration with Reactive Streams
Stream processing from single node to a cluster
A dive into akka streams: from the basics to a real-world scenario
Ad

Viewers also liked (20)

PDF
Reactive Streams, j.u.concurrent & Beyond!
PDF
Reactive Streams 1.0.0 and Why You Should Care (webinar)
PDF
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
PPTX
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
PDF
Akka-chan's Survival Guide for the Streaming World
PDF
Managing Binary Compatibility in Scala (Scala Days 2011)
PDF
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems (Soft-Sha...
PDF
Streams processing with Storm
PDF
Scala Past, Present & Future
PDF
Enterprise Development Trends 2016 - Cloud, Container and Microservices Insig...
PDF
Distributed Systems Done Right: Why Java Enterprises Are Embracing The Actor ...
PDF
Akka cluster overview at 010dev
PPTX
Akka: Введение
PDF
Streaming data to s3 using akka streams
PDF
Effective Scala (SoftShake 2013)
PDF
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
PDF
Akka - A Brief Intro
PPTX
Akka Actor presentation
PDF
Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)
PPTX
Benefits Of The Actor Model For Cloud Computing: A Pragmatic Overview For Jav...
Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams 1.0.0 and Why You Should Care (webinar)
Understanding Akka Streams, Back Pressure, and Asynchronous Architectures
Lessons Learned From PayPal: Implementing Back-Pressure With Akka Streams And...
Akka-chan's Survival Guide for the Streaming World
Managing Binary Compatibility in Scala (Scala Days 2011)
Go Reactive: Event-Driven, Scalable, Resilient & Responsive Systems (Soft-Sha...
Streams processing with Storm
Scala Past, Present & Future
Enterprise Development Trends 2016 - Cloud, Container and Microservices Insig...
Distributed Systems Done Right: Why Java Enterprises Are Embracing The Actor ...
Akka cluster overview at 010dev
Akka: Введение
Streaming data to s3 using akka streams
Effective Scala (SoftShake 2013)
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
Akka - A Brief Intro
Akka Actor presentation
Lightbend Lagom: Microservices Just Right (Scala Days 2016 Berlin)
Benefits Of The Actor Model For Cloud Computing: A Pragmatic Overview For Jav...
Ad

Similar to Akka streams (20)

PDF
Mirco Dotta - Akka Streams
PDF
Springone2gx 2014 Reactive Streams and Reactor
PPTX
Multi-Datacenter Kafka - Strata San Jose 2017
PPTX
Spark + AI Summit 2019: Apache Spark Listeners: A Crash Course in Fast, Easy ...
PDF
Apache Spark Listeners: A Crash Course in Fast, Easy Monitoring
PDF
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
PDF
Headaches and Breakthroughs in Building Continuous Applications
PPTX
Spark + AI Summit 2019: Headaches and Breakthroughs in Building Continuous Ap...
PDF
Akka in Production - ScalaDays 2015
PPT
Stream, Stream, Stream: Different Streaming Methods with Spark and Kafka
PDF
Introduction to Akka Streams
PDF
Guide to Spring Reactive Programming using WebFlux
PDF
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
PDF
Reactive Streams
PDF
Learn from HomeAway Hadoop Development and Operations Best Practices
PPTX
Tuning kafka pipelines
PDF
Building Big Data Streaming Architectures
PPTX
RxJS and Reactive Programming - Modern Web UI - May 2015
PDF
Akka Streams at Weeronline
PDF
introductiontoapachekafka-201102140206.pdf
Mirco Dotta - Akka Streams
Springone2gx 2014 Reactive Streams and Reactor
Multi-Datacenter Kafka - Strata San Jose 2017
Spark + AI Summit 2019: Apache Spark Listeners: A Crash Course in Fast, Easy ...
Apache Spark Listeners: A Crash Course in Fast, Easy Monitoring
Introduction to Apache Beam & No Shard Left Behind: APIs for Massive Parallel...
Headaches and Breakthroughs in Building Continuous Applications
Spark + AI Summit 2019: Headaches and Breakthroughs in Building Continuous Ap...
Akka in Production - ScalaDays 2015
Stream, Stream, Stream: Different Streaming Methods with Spark and Kafka
Introduction to Akka Streams
Guide to Spring Reactive Programming using WebFlux
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Reactive Streams
Learn from HomeAway Hadoop Development and Operations Best Practices
Tuning kafka pipelines
Building Big Data Streaming Architectures
RxJS and Reactive Programming - Modern Web UI - May 2015
Akka Streams at Weeronline
introductiontoapachekafka-201102140206.pdf

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Modernizing your data center with Dell and AMD
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Encapsulation theory and applications.pdf
PDF
Approach and Philosophy of On baking technology
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Machine learning based COVID-19 study performance prediction
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPT
Teaching material agriculture food technology
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
cuic standard and advanced reporting.pdf
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Understanding_Digital_Forensics_Presentation.pptx
Modernizing your data center with Dell and AMD
Digital-Transformation-Roadmap-for-Companies.pptx
Advanced methodologies resolving dimensionality complications for autism neur...
Encapsulation theory and applications.pdf
Approach and Philosophy of On baking technology
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Big Data Technologies - Introduction.pptx
Diabetes mellitus diagnosis method based random forest with bat algorithm
Machine learning based COVID-19 study performance prediction
Reach Out and Touch Someone: Haptics and Empathic Computing
Teaching material agriculture food technology
Review of recent advances in non-invasive hemoglobin estimation
Per capita expenditure prediction using model stacking based on satellite ima...
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
NewMind AI Weekly Chronicles - August'25 Week I
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx

Akka streams