amacgregor

amacgregor

GenStage usecases and best practices

Elixir Noob here, I’m looking for advice about GenStage and some general guidelines when designing systems with Elixir.

At a high level, I’m looking to build a system where the end-user can modify/select each stage of a data pipeline, the start and end of said pipeline will always be the same, but the end user can add/activate a new stage that will do the additional computation.

Will using GenStage and the Flow module be a good fit for the usage I described? if so any examples or advice anyone can offer in regards to the implementation?

Cheers!

Most Liked

josevalim

josevalim

Creator of Elixir

Your description of the problem is very vague to say if GenStage or Flow is a good fit. I would first worry about writing the application and business domain. As an Elixir beginner, there are a couple things you would need to learn before dynamically managing GenStage pipelines, such as managing simple processes, and you can reevaluate later if you need the performance characteristics or the backpressure provided by GenStage.

To put it shortly, start with the simplest abstraction until you are familiar and you are sure you need more complex ones.

LostKobrakai

LostKobrakai

Not really. GenStage servers are just GenServers as well, but they have some extra functionality build on top for handling events in a chain of producers and consumers (or producer/consumers which do both things), reducing the boilerplate needed to set those up. Flow is another layer of abstraction on top of that which handles common cases like faning out to multiple processes and reducing those back at a later stage.

All this could be done using plain GenServers as well, but you’d need to write a ton more code to wire things up. Also each of those servers, be it a genserver or genstage instance still works syncronously on it’s own events. It’s multiple of those servers, which makes things async.

amacgregor

amacgregor

Thank you Jose, then I’ll do as you advice and go work on my basics before jumping into GenStage

Where Next?

Popular in Questions Top

gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
pgiesin
This should be a simple problem but I just can’t seem to figure it out. I have a standalone Elixir app that won’t find the database. Dep...
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list....
New
chrisalley
ExUnit now has describe blocks which is a welcome addition coming from RSpec. In the docs, it states that nested hierarchies of describe ...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
Mooodi
Given a string, how can I get access to its character by index? Enum.at("my_string", 2) doesn't work. Or rather, not char, but a substr...
New
wernerlaude
In AR this is so simple @articles = current_user.articles How to do in Ecto? def index(conn, _params) do current_user = conn.assig...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New

Other popular topics Top

JDanielMartinez
Hi! May someone helps me, please! I have two apps into an umbrella project: the first one is Database, which manages queries, and the se...
New
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
JakeBecker
TL;DR: I’ve just released an implementation of Microsoft’s IDE-independent Language Server Protocol for Elixir. It adds language support ...
1140 51847 244
New
sergio_101
I am VERY much an elixir newbie. I have taken one elixir course and one phoenix course on Udemy. During that course, I saw the instructor...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod -- where is this set? Thanks.
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
myronmarston
The Elixir Typespec docs show the following syntax for keyword lists in typespecs: # ... | [key: type] # keyword lis...
New
mcarvalho
What is the difference between System.get_env and Application.get_env? For example, what are best practices to use one versus another.
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement