hubertlepicki

hubertlepicki

I have been thinking about GenEvent today when reading the fantastic book “Designing for scalability with Erlang/OTP”. I do not really like it (gen_event, I love the book), in fact, I can hardly justify using it in any but the simplest cases where nothing can go wrong. It is difficult to set up correctly and adjust to different use cases, I think mainly because it runs the handlers in process of manager. But since here are so many great more experienced Elixir and Erlang devs than me, I may as well reach out to get your opinions on the topic. Two questions from myself:

  1. Is GenEvent really that bad as I think it is, or do you actually use it and can recommend doing so?

  2. What GenEvent alternatives would you recommend?

You already got my opinion on 1, just a quick note on how I have been dealing with events handling now: I use third party gproc lib and implemented my own solution based on it’s pub/sub use case. My event handlers are started as stand alone processes (GenServers with handle_info callbacks in fact) and supervised/restarted entirely separately than my event manager.

I think @josevalim is working on gen_broker (a.k.a. gen_router), and it may be interesting alternative in the future, but I do not think it’s ready just yet.

Showing Posts 1 to 7

sasajuric

sasajuric

Author of Elixir In Action

For the reasons you mention I’m not a fan of GenEvent myself. I also prefer gproc with property based registration and discovery. With this approach error recovery is easy to do using supervisors, while the discovery of subscribers is left to the registry.

Based on the ElixirConfEU keynote by @josevalim, it looks like gen_broker will support something similar, but with the additional ability to apply back-pressure. It’s hard for me to comment on this until it lands. So for now, my go-to approach for notifying an unknown number of subscribers is gproc.

I should mention that I consider gproc only as a local registry, and don’t use it as a global one. For issuing notifications in the cluster I’d recommend Phoenix PubSub. In the next version it will be a separate library, so you don’t even need to depend on the entire Phoenix to use it. Another alternative is pg2. It doesn’t have all the goodies of the next PubSub (most notably presence), but on the upside, it’s available out of the box, so no need to add another dependency.

hubertlepicki

hubertlepicki OP

@sasajuric thanks for the tip about Phoenix PubSub. It looks on a first sight that the work is really advanced / close to being completed on extracting it. So it may be very much usable already: GitHub - phoenixframework/phoenix_pubsub: Distributed PubSub and Presence platform for the Phoenix Framework · GitHub

eksperimental

eksperimental

Jumping in just to mention that once GenBroker makes it to Elixir (probably v1.3), GenEvent will be deprecated from Elixir
so you know where you energy goes to if you are planning on learning GenEvent

hubertlepicki

hubertlepicki OP

I am just watching the keynote Jose gave on this Elixir Conf EU, and it is very much relevant and describes the plans ref GenEvent alternative.

hubertlepicki

hubertlepicki OP

And the second published talk, by @chrismccord is also very much relevant. Looks like phoenix_pubsub is going to be perfect replacement for GenEvent (and more) for classic pub/sub use cases and process groups etc.

hubertlepicki

hubertlepicki OP

I will probably wrap it up in a blog post. But I have tried pg2, gproc, also stand-alone phoenix_pubsub. Then I found this gem:

https://github.com/ostinelli/syn

it has some nice features, like sending message and collecting responses (multi_call), pub/sub and presence out of the box. Does seem to work great in clustered env, while I had real trouble getting gproc to work.

Gproc seems to depend on gen_leader which is not like one library but dozen of forks, forks of forks, and people would not agree which one is least buggy. This seems like a real mess, which is an indication to me to avoid the project at all.

ijunaidfarooq

ijunaidfarooq

Did you try to replace GenEvent with Phoenix PubSub? and how it went?

— All posts loaded —

Where Next? Top

Trending in Discussions Top

AstonJ
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
2977 94592 917
New
cblavier
Hey there, It’s been more than a year since we started using LiveView as our main UI library and building a whole library of UI componen...
New
mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
heathen
Quite interesting article Google brought me. Didn’t find any mentions about it here. What do you think in general? Would you use togethe...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
axelson
Hi there! :wave: @frigidcode and I (but mostly him) have been running an Elixir Book club, we’re almost done with Designing Elixir Syste...
New
budgie
A little off-topic, but I feel like people here have a good head on their shoulders. I used to be quite good at making software. Was luc...
New

Other Trending Topics Top

GenericJam
Edit: 2026 May 15 - This post is archived. Mob is alive!! Main docs: mob v0.7.11 — Documentation A bit of explanation for the slightly c...
New
JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
georgeguimaraes
Just published claude-code-elixir, a plugin marketplace for Claude Code with Elixir support. These are the plugins I’ve been using for my...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews