Reactive Programming with Akka Streams

Akka-Streams is one of the many interesting and very useful Akka modules. Akka is a powerful actor / reactive framework for the JVM. Akka is an extremely high-performance library -- you can do Up to 50 million msg/sec on a single machine. Small memory footprint; ~2.5 million actors per GB of the heap. Akka is also resilient by Design and follows the principles of the Reactive Manifesto. Akka follows Erlang Actor philosophy/ideas.  Many big and successful companies use Akka in production like Blizzard, Intel, Wallmart, Paypal, Amazon, Zalando, Netflix, IGN, VMware UBS, and much many more others.



Actors and Protocols

Actors are a nice abstraction and programming model however they are not ideal for every single kind of problem. Some problems fit very well with actors others don't. When you are using Akka you are pretty much defining a protocol like a state machine. You will define series of messages that your actors with a share in order to do your work.  However, working with Akka has some pitfalls like you need to model your problem with actors and depending on what you do you could lose messages and some transformations might be harder to do it -- actors could be used to deal with streams work however would be less productive and less natural so that's where Akka stream come to play.

Akka Streams

Akka Streams is an Akka module which will use Akka under the hood. Akka Streams has the materialization concept where you will be able to convert a Stream(sequences of Source -> Sink and Graph work) into a set of actors into an actor-system, Akka streams with use Akka to run your computation work.


You can think about Akka Streams as a big pipeline of operations. Where you will have a SourceShape[T+] which pretty much is a publisher and will provide data. This Source will publish data to a subscriber FlowShape[-I,T+] then you can apply transformations or even continue to pipe more things.  Akka stream is nice because you can have functional programming similar to apache spark for instance but truly reactive and low latency. Akka Streams can also handle slow consumers / fast producers applying back pressure.

Show me the Code

Sometimes the best way to see something is going down to the code. So Let's see some code samples. I will show some nice things you can do with Akka Streams and then you can take your own conclusions.


Here you can get the full project code with sbt just check it out on my GitHub.

Cheers,
Diego Pacheco




Popular posts from this blog

Telemetry and Microservices part2

Installing and Running ntop 2 on Amazon Linux OS

Fun with Apache Kafka