How is the actor model used

actor-modelcomputer scienceconcepts

I have read a bit about the actor model, but don't really understand how to use actors in a real world situation – how to model a problem with them.

Can someone please explain? A simple example or links to examples would be much appreciated.

Best Answer

Actors, in the sense of modeling actions, with messages, etc is a way of modeling software that provides a couple of useful items...

  1. Actors can live on a single thread, allowing non-thread-safe/non-concurrent operations to happen without a bunch of locking magic. An actor will respond to messages in its inbox. When you want it to process a command you send it a message and it will take care of them in the order they are received. Just like a normal queue. Thread safe is killer here, and I use this in a number of open source projects I work on.

  2. In some languages, Scala for example, it's easy to turn actor based code in a single process into a distributed system by breaking apart the actors and turning the channels they communicate over into remote channels. This changes between implementations on how easy it is, but it's an awesome feature.

  3. Helps focus on Task Based events rather than CRUD events. CRUD is simple but it's just like interacting with a filing cabinet. If we can provide more value than that in the software we produce, why are we doing it? Tying multiple actions to a single "Update" command in a task based system is more useful than just saving to the DB. This also gets into stuff like CQRS.

Related Topic