Understand GenServer, Supervisor strategies, DynamicSupervisor, Registry, and the Application behaviour in OTP.
0 / 5 completed
1 / 5
What is a GenServer in Elixir OTP?
GenServer: wraps a loop that processes messages from the process mailbox. handle_call receives the message and a from pid, and must reply. handle_cast is fire-and-forget. The OTP framework provides tracing, timeout, hibernation, and supervisor integration for free.
2 / 5
What does a Supervisor in OTP do?
Supervisor: the "let it crash" philosophy relies on supervisors. Rather than defensive error handling everywhere, processes crash cleanly and supervisors restart them in a known good state. This isolates failures: a crashed worker does not corrupt shared state or bring down the whole system.
3 / 5
What is a DynamicSupervisor used for?
DynamicSupervisor:DynamicSupervisor.start_child(sup, child_spec) spawns a new worker on demand. Each new WebSocket connection or job can get its own supervised process. When the process exits, the supervisor removes it without affecting other children, unlike a static supervisor which has a fixed child list.
4 / 5
What is the Registry module in Elixir used for?
Registry:Registry.register(MyRegistry, "room:42", meta) lets a process register itself under a key. Other processes find it with Registry.lookup(MyRegistry, "room:42"). It supports unique (one process per key) and duplicate (many per key) modes, and cleans up dead process registrations automatically.
5 / 5
What is the Application behaviour in Elixir OTP?
Application:use Application; def start(_type, _args) do Supervisor.start_link(children, strategy: :one_for_one) end. The Mix release or mix run boots all declared OTP applications in dependency order, each starting their own supervision tree, forming the complete system.