State Management in Akka.NET
One of the primary use cases for Akka.NET is for building highly available, stateful applications. State is an important element of high performance applications because it allows systems to react to end-user input in real-time; this type of work simply isn't feasible using traditional CRUD (Create, Read, Update, and Delete) architectures that outsource 100% of their state management down to an external database.
Here's a concrete example from Aaron Stannard, one of the founders of Akka.NET, describing the need for in-memory application state using and how traditional "database first" approaches failed abysmally prior to creating and using Akka.NET itself to solve his company's problem:
So given this radical change in architecture, "application state as source of truth" instead of "database as source of truth," what are some of the challenges and best practices Akka.NET developers should learn?
Akka.Persistence Failure Recovery and Supervision
Akka.Persistence is one of the tried and true tools for making it easier to work with state in Akka.NET. It provides developers with a simple, repeatable model for backing up their application state by saving it into a durable store, such as a database, so it can be recovered later for future use or in the event of a crash. Today, there are dozens of different Akka.Persistence plugins that support different database products such as SqlServer, MySQL, MongoDb, Redis, Azure Table Storage, and more.
However, in order for Akka.Persistence to do its job it must be able to read and write from the underlying database its plugins target. So, what are Akka.NET developers to do in the event that the database becomes temporarily unavailable?
PersistenceSupervisor actor - an in-memory actor introduced as part of the Akka.Persistence.Extras NuGet package. The
PersistenceSupervisor works in tandem with your persistent actors to ensure that all events get persisted even in the event that the underlying database becomes unavailable.