Actor Model
Concept from 1973 by Carl Hewitt:
Actor is the fundamental unit of computation embodying processing, storage, and communication.
Fundamentals #
- All computation occurs inside of the actor.
- Each actor has an address.
- Actors may create new actors, send messages to them and changing their own behavior to handle new messages (e.g., change the state).
An actor does not exist isolated, it works in tandem with others and are arranged in hierarquy:
- Actors can split up and delegate tasks to child actors.
- Child actors are supervised and delegate their failures back to their parent.
Anatomy #
Each actor has:
- An address.
- An mailbox.
- An dispatcher.
Messages are sent to an Actor Address which are enqued in the mailbox and only then are dispatched for processing. Note that, only one message is dispatched at a time leading to the ilusion of single thread (there may be multiple actor within the same system, each one handling messages in different threads).
It is important that that actors communicate exclusively through messages and do not shared state to ensure Strong Consistency! Moreover messages must be immutable.
Reactive Systems #
In the context of Reactive Systems, Actor model is a reactive tool, a paradigm that:
- Actors only communicate through asyncronous messages.
- Message driven - All communication between actors is done with async non-blocking messages.
- Abstractions provide elasticity and resiliency.
Akka uses the actor model - https://doc.akka.io/docs/akka/current/typed/guide/actors-intro.html?language=scala
The message driven system provides location transparency, i.e., the technique remainins the same regardless of where the actors are. This allows better resiliency and elastic (hmm.. questions on this bit). This is different from “Transparent remoting” as this hides potential networking issues while making it seem like local calls. Location transparency makes the opposite which is makes local calls seem like remote calls, therefore whoever uses is aware that there are potential failures.
Akka Actors is an implementation of the Actor Model.