Introduce GenStage

Learn how the GenStage library in Elixir uses stages to build data processing pipelines.

The history of GenStage

GenStage was initially developed by José Valim, the creator of Elixir, and released in July 2016. As he described it in the official announcement:

“GenStage is a new Elixir behaviour for exchanging events with back-pressure between Elixir processes.”

The previous chapter uses the GenServer behaviour to build long-running server processes. The GenStage behaviour, as its name suggests, builds stages. Stages are also Elixir processes, and they’re our building blocks for creating data processing pipelines.

Stages

Stages are simple but very powerful. They receive events and use them to do useful work. They can also send events to the next stage in the pipeline. We can do that by connecting stages to each other and creating something like a chain, as we can see here:

Get hands-on with 1200+ tech skills courses.