Actor Model in Nutshell

Krishna Kumar Tiwari
3 min readJan 28, 2019

--

Actor Model is a conceptual concurrent computation model, came into picture in 1973. It defines some general set of guidelines how system components should interact in concurrent computational environment. Most famous implementations for Actor Model are Akka & Erlang.

An Actor in Actor Model is an fundamental unit of computation, it can perform below actions.

  • Create another Actor
  • Send a message
  • Designate how to handle the next message

Actors are light weight and it is very easy to create millions of them as they take fewer resources than Threads

Actor Model: Conceptual Concurrent Computation Model

As showed in the diagram above, an Actor has it own private state and a mail box (similar to message queue). Mailbox contains the message which the Actor has got from others, message here means Simple Immutable Data structures. Messages are processed in FIFO order.

Actor decided on how to handle the next message based on it’s current private state, for example if an Actor is keeping the count of a particular value(X=10) and received a message to add two to the value, it will update it’s private state and keep X=12. X=12 will be available for the next message in queue.

Actors are isolated in nature and they don’t share memory

Actor’s private state can only be changed by processing a message, it can handle only one message at a time and they work asynchronously, it means one Actor never waits for a response from anther Actor.

Actors interact with each other through messages only. It can only interacts with Actors whose address it has (same like our phonebook)

  • Actors which it has created (hence already know the address of child actors)
  • Extract address for messages it receives

In distributed scenario it possible that Actors are on different machines hence they communicate to address with messages, an address can be a local address or a remote address.

Using Actor model one can create Self Healing System or Fault tolerant systems. The First Actor created we can call it as master, it creates multiple other actors which are like supervisor to the master. If a actor dies or not responsive, it’s supervisor can primary take below calls to make it self healing system.

  • Restart
  • Redirect the message to another Actor

Pros of Actor Model

  • Easy to scale
  • Fault Tolerant
  • No shared state

Cons of Actor Model

  • Mailbox can overflow
  • Susceptible to deadlocks

Actor Model is conceptualised well and it makes perfect sense to use the Actor Model if one is designing concurrent systems. I would love to know more scenarios where you have used Actor Models in practice.

Thanks for reading this, please share your thoughts, feedback &ideas in comments. You can also reach out me on @simplykk87 on twitter and linkedin.

References

https://www.brianstorti.com/the-actor-model/

https://www.youtube.com/watch?v=ELwEdb_pD0k

--

--

Krishna Kumar Tiwari

40 Under 40 Data Scientist | Mentor at Atal Mission, Niti Aayog | Founder ML-Ai Community (ml-ai.in) | IIT-G