Top 3 Erlang Supervision Strategies Explained
Erlang supervisors employ key strategies to manage process failures: 'one_for_one' restarts only the failed child process, ideal for independent components. 'one_for_all' restarts all sibling processes if any one fails, suitable for tightly coupled systems. 'rest_for_one' restarts the failed child and all subsequent children in start order, used for linear dependencies.
The top 3
- One-for-One: The Default for Independent Processes: This strategy restarts only the child process that failed, leaving other supervised processes unaffected. It is the most common and default strategy, ideal when child processes are independent and do not share state, preventing cascading failures across unrelated components.
- One-for-All: Ensuring Coherent State for Dependent Processes: When any child process under a `one_for_all` supervisor terminates, all other children are also terminated, and then all children (including the failed one) are restarted. This strategy is crucial for tightly coupled groups of processes where a failure in one necessitates a complete reset of the group to maintain consistent state.
- Rest-for-One: Managing Linear Dependencies Efficiently: This strategy restarts the failed child process and all subsequent child processes that were started after it in the supervisor's child specification list. This is particularly useful for scenarios with linear dependencies, where later processes rely on the correct state of earlier ones, ensuring that the dependent processes are also reset to a known good state.
Sources
Open the full topic