Distributing State in Akka.Cluster Applications
Consistent Hash Distributions and Clustered Routers
One of the most frequently asked questions about Akka.Cluster I receive is “how do I reliably distribute state in an Akka.NET Cluster?”
Akka.Cluster is primarily for building highly available, soft real-time applications in server-side environments - and one of the concepts that is essential to delivering “soft real-time” is statefulness.
Stateful applications are becoming more and more common because they execute types of work that are infeasible and impractical with stateless CRUD applications, but they also introduce new types of challenges such as:
- How do I evenly distribute state across my cluster? No “hotspots.”
- How do I find the state I need within my cluster?
- What happens to my state if a stateful node goes down?
- How do I guarantee that my state is modified safely? Consistent histories for state, in other words.
We can address, at a high level, all of these questions using a tool built into Akka.Cluster: consistent hash routers and Cluster.Sharding.