What is the actor model?
The actor model treats actors as the fundamental unit of computation. Each actor is an isolated entity that:- Processes messages sequentially (one at a time)
- Maintains private state (no shared memory with other actors)
- Communicates exclusively via message passing
Why use actors?
Actors provide a natural model for concurrent and distributed systems:- Encapsulation β State is private; no locks or mutexes needed inside an actor
- Location transparency β You send to a PID; the framework routes locally or remotely
- Fault isolation β A failing actor does not corrupt others; supervision handles recovery
- Scalability β Actors can be distributed across nodes; the cluster manages placement
Core concepts
| Concept | Description |
|---|---|
| Actor | The fundamental unit. Receives messages, updates private state, spawns children, sends messages. |
| ActorSystem | The runtime host. Manages lifecycle, messaging, cluster membership, and remoting. See Actor System. |
| PID | Process identifierβa live handle to a running actor. Used for all interactions. |
| Path | The canonical location of an actor: goakt://system@host:port/path/to/actor. |
| Mailbox | Each actor has one. Messages wait here until the actor processes them. |
Actor hierarchy
Every actor lives inside a tree. GoAkt creates guardian actors at startup:- Root β Top of the tree
- System β Parent of internal actors (dead letter, scheduler, etc.)
- User β Parent of all user-spawned actors
Single-threaded execution
GoAkt guarantees that only one goroutine processes messages for a given actor at any time. You never need internal locks to protect actor state. Messages are processed sequentially from the actorβs mailbox (FIFO).The Actor interface
Every actor must implement theActor interface:
| Method | When called | Purpose |
|---|---|---|
| PreStart | Once, before the actor processes any message | Initialize dependencies, caches, or recover persistent state. Return an error to prevent startup; the supervisor handles the failure. |
| Receive | For each message in the mailbox | Handle messages. Use a type switch on ctx.Message(). Call ctx.Unhandled() for unknown types. |
| PostStop | When the actor is about to shut down | Release resources, flush logs, notify other systems. Called after the mailbox is drained. |
PreStart, not in constructors. The framework guarantees
single-threaded execution per actor, so no locks are needed inside Receive.
Further reading
- Brian Storti: The Actor Model β Short introduction
- Messaging β Tell vs Ask, message types
- Actor Lifecycle β Spawn, stop, state transitions