↓ Ir para o conteúdo principal

← todas as notas

📎 Webclip

Building Distributed Systems in Elixir: Part 5 — Supervisor From Scratch

The article shows how to build a small supervisor without GenServer or OTP Supervisor. It links two workers to a supervising process, traps exits, and uses a child map to identify which worker died so only that worker is restarted.

It also explains the difference between abnormal and normal exits, the fresh state of replacement processes, and the limits of the manual approach compared with OTP supervision.

Reading notes
#

  • The supervisor starts two linked workers and keeps a map from PID to logical worker name.
  • Process.flag(:trap_exit, true) turns exit signals into {:EXIT, pid, reason} messages.
  • An abnormal exit removes the dead PID, starts a replacement with the same name, and stores the new PID.
  • A normal exit removes the worker without restarting it.
  • The demo polls for a new PID only to verify the asynchronous restart.
  • Restarting a worker restores the process, not its private in-memory state.
  • The manual implementation does not cover restart limits, shutdown timeouts, structured child specs, or nested supervision.
  • OTP Supervisor is presented as the production-ready version of these ideas.

Series
#

Building Distributed Systems in Elixir, by krishnadaspc. Research: Distributed Systems Patterns.