Skip to content

Actor model

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

One line: Actors are isolated units with a mailbox: each handles one message at a time, and can send messages, create actors and change its own state.

Also called: actors, mailbox.

How it connects

flowchart LR
  n_actor_model["Actor model"]
  n_csp["Communicating sequential processes"]
  n_message_passing["Message passing"]
  n_otp_behaviours["OTP behaviours"]
  n_supervision["Supervision"]
  n_actor_model ---|vs| n_csp
  n_actor_model -->|is a| n_message_passing
  n_otp_behaviours -->|uses| n_actor_model
  n_supervision -->|uses| n_actor_model
  classDef center stroke-width:3px
  class n_actor_model center
  classDef outside stroke-dasharray: 4 3
  class n_csp,n_message_passing,n_otp_behaviours,n_supervision outside

In each language

C# Orleans ↗, whose virtual actors are called grains
Kotlin the channel-based actor builder is marked @ObsoleteCoroutinesApi
Swift an actor is a reference type that lets only one task at a time access its mutable state
Erlang and Elixir processes are the actors, each with a mailbox it reads with receive (Elixir ↗); a GenServer is a process that keeps state and serves calls
Elsewhere Akka ↗: an actor processes one message at a time, so its state needs no locks

Where to read more