alexandru-calinoiu

alexandru-calinoiu

I have a production app that uses commanded, the event handlers are started using a supervisor with the default retry values (max restarts 3, max seconds 5).

The problem is that if one of the command event handlers restarts more than 3 times in 5 seconds it will take the entire app down with it because it will kill all the other event handlers and then all the way up to the web server.

What are my options to solve this issue?

Showing Posts 1 to 3

LostKobrakai

LostKobrakai

Unrelated to commanded specifically, but using the supervision tree to handle expected failures is not a great idea. The restart behaviour of supervisors is meant to keep a system up and running (as in available) and if it fails to do so stop trying, so someone higher up can take a look. Eventually that’s someone on call. That’s what you’re seeing. You could allow more failures to happen before giving up, but at least after a few retries not having backoff is considered waistful.

Generally you should figure out what you do want to happen instead of letting the app fail and the tradeoffs involved. With that you can start looking into how to best implement that, especially given commanded is likely the tool to queue up the events for processing. Not sure what options it provides to deal with failing events over time.

I’d also suggest considering what classes of errors might result in errors of your event handlers. E.g. a bug is unlikely to resolve without a software update, a network issue might resolve over time. You might even want to handle them differently per type of error.

slashdotdash

slashdotdash

You should implement the error/3 callback function in event handlers to handle problematic events so that the event handler does not restart on error.

The example error handling in the docs shows a simple strategy to retry X times and then log and skip an event that cannot be handled.

xpg

xpg

We ended up solving this by setting up a supervisor that allows our event handlers to crash, without restarting them. At runtime, we can query the supervisor about which event handlers / projectors are stopped and not restarted.
Our operations team is notified of this, so that they can investigate the situation.

The reason we did not go with skipping events, is that we’re afraid of continuing handling events, if there is one we cannot handle.

The only time we have needed this, it worked like a charm: We had an event being introduced by accident, that was unhandled in a projector. The projector got stuck and died. The rest of the system kept running, but operations were aware of the issue. We could then handle the situation (which in this case was done by blanking out the event), and restart the projector.

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kpanic
Hi everyone, I am toying with the idea of building a “match maker” for giving personal help to people that wants to start coding. I sta...
New
nseaSeb
Hello, I know there is an approach for handling lists that allows for optimized traversal, but I can’t recall the specific method (somet...
New
brecabral
Documentation While reading the Scoped Routes section, I noticed that the documentation currently refers to a problem without explainin...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
asweet-confluent
I recently noticed that Elixir’s Logger defaults its primary log level to :debug when no :logger, :level application configuration is pre...
New
apz
I’m new to elixir and just tried to install the elixirLS extension for VScode(ium) and it is throwing some errors that I would like help ...
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
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
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
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
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

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews