How to make a Phoenix app resilient?

Good afternoon peoples.

I’m starting studies with Elixir and Phoenix and wanted a direction to make a resilient application.

Thank you.

That’s a very open ended question, we’re likely unlike to be more useful than a Google search here. Perhaps you could give some more context on your application, what it does, how it is run, what your team is like, etc :slight_smile:


If you are just starting out with Elixir (and probably the whole BEAM stuff), it helps a lot to first try to understand how applications are built with processes and not the way most other languages do it.

It can take a while to “reprogram” your brain into this way of thinking and many things will be confusing at first, but after some time you automatically think about the process architecture when you want to build something.

For building resilient applications, it is really important how all these processes interact with each other and what their lifecycles are. A good tip is to keep them as small and specialised as possible to avoid failures that affect other parts not related to the initial error that could have occurred somewhere.

For example, I am building a backend for a GPS tracking mobile app. Each tracking “session” starts a Supervisor under a DynamicSupervisor. That Supervisor then has 3 child processes. State, Timeout, Broadcaster. The State process only handles the state of the session, the Broadcaster process calls itself every minute and sends the latest known position to another system and the Timeout process terminates the whole “session” (Supervisor + 3 Genservers) if there is no activity in X amount of minutes.
This is a pretty “stable” setup. If the Broadcaster process throws an error somehow because e.g. the network is funky (in my case, I handle such things manually tho), it won’t take down the State and Timeout processes. It simply restarts and everything still works. If the State process crashes, the state will be gone but it is very very unlikely that the process will throw an error because all it does is to mutate a map based on messages I send to it.

I hope this was a somewhat useful answer.