welcome to section seven acha streams in
the previous section we introduced you
on how to test actors in this section we
will introduce the new module in Acker
that is
akka streams at the moment of recording
streams are in version 1.0 experimental
and slight API changes may still happen
however it's stable enough to be used
already so let's take a look here we
will take a quick look at intro to akka
stream and its terminologies then we
will implement our stream application
reactive tweets and test the reactive
tweets application we will then work
with graphs and with stream IO let's
start our trip in the stream world in
the first video we will take a look at
the problems of fast data and streaming
processing world and while we should be
using occur streams next we will
introduce the basic terminology in akka
streams and implement our first stream
up let's start then big data has been
around for quite a while and it's
usually batch processing in the current
world though we're starting to talk
about fast data which means we want to
process the data right away when it hits
our service for example akka streams are
a library which allows implementing
either style of application and
guarantees that it will execute
unbounded buffer sizes will not cause
out of memory errors the two main
problems streaming data solutions need
to tackle are blocking and back pressure
to survive high load scenarios blocking
can happen in a pull based system this
means a consumer pulls data from the
producer blocking takes place when there
is no data to pull this is safe for the
consumer it will not run out of memory
however it is also very slow to build
systems based purely on pulling data the
other problem is back pressuring to fast
producers of data when working with
pushing data in pull systems it's not as
visibly needed however they are slow and
we want our systems to be fast the need
for back pressure
when the producer wants to create more
data than the consumer can handle which
can cause the consumer to crash let's
take a real-life example to understand
these problems let's imagine we have a
source of water and a sink which we want
to fill and we have pipes between them
if we decided to put a pump at the end
of the pipes to pull the water the pump
will still work even if there is no
water on the source and if we move the
pump to start off the pipes to push the
water the pump will still work even if
the sink is filled and the water just
overflows to fix our problems we need to
put a pump on the source and cap on the
sink
this means the pump will work when a
source contains water and when the sink
fills the cap will create back pressure
and trigger the pump to stop pumping
this is exactly what akka streams do
when it comes to solve the main problems
on streaming data processing akka
streams describe the solution as a
synchronous dynamic push-pull back
pressure now let's discuss the main
parts of akka streams the main elements
of akka streams our source and sink the
sources where data begins to flow from
it has the output port and no input port
the source in our example may be a river
in applications it may be a query from
the database or HTTP requests requests
bytes the sink is the end of the stream
it has the input port and no output port
in our example we were directing the
flowing water that we have collected in
a sink in real-world applications it may
be the stored data in the database or
data written on a file so we'd have a
file sink as streams can have multiple
processing stages between a source and
the sink we also need to name this
concept in akka
it's called a flow and one can flow the
data via a flow from source by a flow
and finally to a sink if you want to
make things more interesting on the
stream you need to add a flow between
the source and sink a flow can be used
to apply transformations to the data
coming out of a source before putting it
into a sink when connecting the source
to the sink we get a runnable flow a
runnable flow is something we
can start in other words it's a flow
with the sink and a source attached a
complete stream pipeline this is the
most basic complete form you can make in
akka streams this means you must connect
your source with a sink to have a
complete system and your data can flow
through it now let's implement all this
into a simple app akka streams provides
this nice typesafe DSL to build streams
from the actual execution of it is
actually handled by actors underneath
here's how we can build and run a simple
stream we will talk about them in the
next video first let's define our source
let's say we will generate iterators
from 1 to 100 next let's define a flow
let's say we want to multiply it by 2
then let's create our sync in our sync
we will print the elements now let's run
our app
voila Austria map is working this is a
simple application but we have used all
the basic elements on it