A supervisor is a concurrent process manager that starts worker processes, monitors their lifecycles, and restores service when they terminate. This turns individual crashes into recoverable events instead of permanent loss of a system component. section 8.3 section 9.0
A supervisor coordinates its children through a small set of operational rules:
- Starts each child from a child specification, which describes how that process should be started and managed. section 8.3.2
- Uses links, exit trapping, and received exit messages to detect child termination. section 8.3 section 8.3.1
- Applies a restart strategy such as :one_for_one, replacing a failed child without sharing its old state or PID. section 8.3.2
- Takes down its children when it terminates, preventing dangling processes and supporting orderly shutdown. section 8.3.1
Wrapping a to-do system supervisor
defmodule Todo.System do def start_link do Supervisor.start_link( [Todo.Cache], strategy: :one_for_one ) end end Todo.System.start_link() starts the cache and its database processes. If the cache is killed, the supervisor starts a replacement process, which receives a new PID and begins with fresh state. section 8.3.4 section 8.3.2
Supervisors become more useful when arranged as a supervision tree. A parent can manage separate supervisors for the cache, database, and registry, limiting a failure to the smallest meaningful service. If a database worker repeatedly fails, its supervisor can terminate and let the parent restart the database service without disturbing unrelated processes. section 9.1.5 section 9.1.6
The process diagram shows how workers and supervisors organize the to-do system into managed services. section 8.3
This architecture supports “let it crash”: worker code can focus on its intended behavior while supervisors handle unexpected failures and clean-slate recovery. Explicit error handling remains appropriate when a critical process must not crash or an error has a meaningful local response. section 9.3 section 9.4
