0PricingLogin
Scala for Backend Engineering & Functional Programming · Lesson

Source, Flow, and Sink

The streaming building blocks.

The Three Building Blocks

Akka Streams models a data pipeline as a graph of processing stages. The three core linear stages are Source (produces elements), Flow (transforms them), and Sink (consumes them).

A Source has one output, a Sink has one input, and a Flow has exactly one input and one output. Wiring them together describes what should happen, not when.

Defining a Source

A Source[Out, Mat] emits elements of type Out and exposes a materialized value of type Mat. The simplest sources come from in-memory collections or ranges.

Until the stream is run, a Source is just an immutable blueprint that can be reused freely.

import akka.stream.scaladsl.Source

val numbers: Source[Int, akka.NotUsed] =
  Source(1 to 100)

val single: Source[String, akka.NotUsed] =
  Source.single("hello")

All lessons in this course

  1. Source, Flow, and Sink
  2. Transforming Streams
  3. Backpressure
  4. Running a Pipeline
← Back to Scala for Backend Engineering & Functional Programming