Skip to content

Supervision

Category: Communication · Status: stub · Lessons: chapter 05, Message passing (planned)

One line: Letting a failed actor or task crash and having a supervisor restart it, instead of defending against every error inside it — the approach of Erlang and OTP.

Also called: supervision tree, let it crash.

How it connects

flowchart LR
  n_actor_model["Actor model"]
  n_otp_behaviours["OTP behaviours"]
  n_supervision["Supervision"]
  n_otp_behaviours -->|uses| n_supervision
  n_supervision -->|uses| n_actor_model
  classDef center stroke-width:3px
  class n_supervision center
  classDef outside stroke-dasharray: 4 3
  class n_actor_model,n_otp_behaviours outside

In each language

Kotlin SupervisorJob and supervisorScope: a failing child does not cancel the supervisor or its other children
Erlang and Elixir OTP's supervisor keeps its children alive by restarting them, with strategies such as one_for_one; Elixir's Supervisor
The operating system systemd's Restart=, for example on-failure, restarts a service automatically
Elsewhere Akka ↗: a typed actor that throws is stopped unless a supervision strategy, such as restart, says otherwise

Where to read more

  • In the books: The Little Elixir & OTP Guidebook, Benjamin Tan Wei Hao — ch. 5, 'Concurrent error-handling and fault tolerance with links, monitors, and processes'
  • In the books: Concurrency in Go, Katherine Cox-Buday — ch. 5, 'Concurrency at Scale' → 'Healing Unhealthy Goroutines'
  • In the books: Async Rust, Maxwell Flitton, Caroline Morton — ch. 8, 'The Actor Model' → 'Creating Actor Supervision'
  • In the books: Learning Concurrent Programming in Scala, Aleksandar Prokopec — ch. 8, 'Actors' → 'Actor supervision'
  • In the books: Effective Concurrency in Go, Burak Serdar — ch. 10, 'Troubleshooting Concurrency Issues' → 'Detecting failures and healing'
  • In the books: Erlang and OTP in Action, Martin Logan, Eric Merritt, Richard Carlsson — ch. 1, 'The foundations of Erlang/OTP' → '– Erlang’s fault tolerance infrastructure'