personal-page/_master_wiki/void/Readwise/The Actor Model in 10 Minutes.md

3.6 KiB
Raw Blame History

The Actor Model in 10 Minutes

rw-book-cover

Metadata

[!tldr] The actor model is a conceptual model for concurrent computation that uses actors as the primitive unit of computation. Actors receive messages and perform computation based on them, similar to objects in object-oriented languages. Actors are isolated from each other and maintain a private state. Messages are sent asynchronously and stored in an actor's mailbox until processed. Actors can create more actors, send messages to other actors, and designate how to handle the next message. The actor model also allows for fault tolerance and distribution across multiple machines.

Highlights

An actor is the primitive unit of computation. Its the thing that receives a message and does some kind of computation based on it. View Highlight)

actors are completely isolated from each other and they will never share memory. Its also worth noting that an actor can maintain a private state that can never be changed directly by another actor. View Highlight)

In the actor model everything is an actor and they need to have addresses so one actor can send a message to another. View Highlight)

multiple actors can run at the same time, an actor will process a given message sequentially. View Highlight)

Messages are sent asynchronously to an actor, that needs to store them somewhere while its processing another message. The mailbox is the place where these messages are stored. View Highlight)

View Highlight)

When an actor receives a message, it can do one of these 3 things: • Create more actors • Send messages to other actors • Designate what to do with the next message View Highlight)

“Designating what to do with the next message” basically means defining how this state will look like for the next message it receives. Or, more clearly, its how actors mutate state. View Highlight)

What Erlang does is simply letting it crash, but make this critical code be supervised by someone whose only responsibility is to know what to do when this crash happens (like resetting this unit of code to a stable state), and what makes it all possible is the actor model. View Highlight)

This makes it possible to create systems that “self heal”, meaning that if an actor gets to an exceptional state and crashes, by whatever reason, a supervisor can do something about it to try to put it in a consistent state again View Highlight)

Another interesting aspect of the actor model is that it doesnt matter if the actor that Im sending a message to is running locally or in another node. View Highlight)