Meet the Supervisor

Learn about supervisors, their properties, and integrate them into our project.

Supervisor

Just like the workplace, where supervisors are held responsible for groups of employees, Elixir supervisors are responsible for the processes assigned to them. Subordinate processes report back to their supervisor to ensure everything runs smoothly. To accomplish this, supervisors come with a set of features that allow them to manage other processes effectively.

  • They can start processes.

  • They can stop processes.

  • They can restart processes in the case of unforeseen system errors.

  • Supervisors are configured to trap exits, so when a supervised process exits with an error, that error will be isolated. Therefore, it won’t propagate further.

All this makes supervisors an important building block for fault-tolerant applications.

Child processes

Supervised processes are called child processes. Any OTP process can be supervised, and we can also add a supervisor as a child of another supervisor. We have to ask the supervisor to start a process we want to manage. This allows us to conveniently build a hierarchy of processes, also called a supervision tree.

Our sender application already has a supervisor in place, which we can see in application.ex:

Get hands-on with 1200+ tech skills courses.