The actor model, briefly

1 min read

Elixir gets judged by its syntax, which is a shame, because the interesting part is the runtime. Every function runs in an isolated process with its own heap, communicating only by message. No shared memory means no locks, and no locks means a whole class of bugs simply doesn’t exist.

What that buys you

A process that crashes doesn’t corrupt anything — it dies. Supervision turns “crash” from an error state into a strategy: let it fail, restart it clean.

defmodule Counter do
  use GenServer

  def start_link(initial), do: GenServer.start_link(__MODULE__, initial, name: __MODULE__)

  @impl true
  def init(initial), do: {:ok, initial}

  @impl true
  def handle_call(:bump, _from, n), do: {:reply, n + 1, n + 1}
end

If you’ve spent years defending shared mutable state with mutexes, the first time a supervisor tree heals a failure you didn’t even notice happening, it clicks.