Actors in .NET and why I think the actor model is so cool

Actors and actor frameworks has been on my personal technology radar for the last couple of years.

So why do I think actors are so interesting ?

When you run into concurrency challenges in traditional Object Oriented programming you have to start using things like lock’s, mutex’s and semaphores. These kind of things are especially challenging when you have to make the solution scale as well. Things like lock’s, mutex’s and semaphores do not resonate very well with high throughput and scalability. This is one of the areas where actors really shine and that is why I find actors so interesting. Furthermore you can run many actors simultaneously and thus use them to build a highly scalable solution.

What is an actor ?

  • An actor is an object with its own virtual thread.
  • You communicate with an actor by sending messages to it.
  • An actor has a input queue containing the messages sent to the actor.
  • The thread processes the messages in the input queue one at a time. Because the actor only processes one message at a time there are no concurrency concerns inside the actor.
  • You communicate out of an actor by sending messages to other actors (or calling functions on other objects).

The actor model is not a new thing it was first described in 1973 (wikipedia), so it is almost as old as SQL.

Actors in .NET

I am primarily working with C# and .NET and I have found two frameworks build on the Microsoft stack that I think looks promising and they are: Azure Service Fabric and Akka.NET.

Why start with Akka.NET ?

Akka.NET is a NuGet package that you can include in your existing projects and start using in a small corner. Azure Service Fabric is more like a platform that you can run your apps inside. Thus Azure Service Fabric requires more setup and configuration to get started. So to get your feet wet with actors in .NET I would recommend Akka.NET.

Akka.NET is a port of Akka from the JVM and it has evolved a lot over the last two years. The Akka.NET documentation is very good and full of code examples.

 

Leave a Reply

Your email address will not be published. Required fields are marked *