Skip to content
vic

elixir-lang/gen_stage

Producer and consumer actors with back-pressure for Elixir

elixir-lang/gen_stage.json
{
"createdAt": "2015-08-26T17:57:36Z",
"defaultBranch": "main",
"description": "Producer and consumer actors with back-pressure for Elixir",
"fullName": "elixir-lang/gen_stage",
"homepage": "http://hexdocs.pm/gen_stage",
"language": "Elixir",
"name": "gen_stage",
"pushedAt": "2025-11-07T10:42:10Z",
"stargazersCount": 1571,
"topics": [],
"updatedAt": "2025-11-20T12:10:02Z",
"url": "https://github.com/elixir-lang/gen_stage"
}

GenStage is a specification for exchanging events between producers and consumers.

This project currently provides the following functionality:

  • GenStage (docs) - a behaviour for implementing producer and consumer stages

  • ConsumerSupervisor (docs) - a supervisor designed for consuming events from GenStage and starting a child process per event

You may also be interested in two other projects built on top of GenStage:

Examples for using GenStage and ConsumerSupervisor can be found in the [examples]!(examples) directory:

  • [ProducerConsumer]!(examples/producer_consumer.exs) - a simple example of setting up a pipeline of A -> B -> C stages and having events flowing through it

  • [ConsumerSupervisor]!(examples/consumer_supervisor.exs) - an example of how to use one or more ConsumerSupervisor as a consumer to a producer that works as a counter

  • [GenEvent]!(examples/gen_event.exs) - an example of how to use GenStage to implement an alternative to GenEvent that leverages concurrency and provides more flexibility regarding buffer size and back-pressure

  • [RateLimiter]!(examples/rate_limiter.exs) - an example of performing rate limiting in a GenStage pipeline

GenStage requires Elixir v1.5. Just add :gen_stage to your list of dependencies in mix.exs:

def deps do
[{:gen_stage, "~> 1.0"}]
end

Same as Elixir under Apache License 2.0. Check NOTICE and LICENSE for more information.