How to deal with JVM crash when using AKKA cluster sharding

490 Views Asked by At

I'm practising Akka cluster sharding function. I started several entities in 3 nodes using sharding function. But I don't know how could the entities be recovered in other nodes when one node is crashed.

Can someone help me to understand how could I do that.

1

There are 1 best solutions below

9
On

The sharding functionality is one of the most powerful features I ever seen in open source projects. I use sharding using akka 2.3.12 version with success over last 2 3 years already. As a rule is desired to have around 10 shards per node, but my deployment is using 5 nodes and I have 20 shards per node and works just fine.

Has to be understood that the sharding is only a routing logic that gives you location transparency of where an actor managed by sharding functionality is actually instantiated (what node, and what shard).

Now regarding recovery of the actor: if your actor has state accumulated by the commands sent, that is important for your business then means you have to persist received commands and be able to recover (CQRS & Event Sourcing) from some persistence available to all nodes. For this akka provides http://doc.akka.io/docs/akka/2.4.16/java/persistence.html capabilities, this documentation is very well structured and gives you enough information about how this recovery can be achieved. As a persistence source I used akka persistence with C* plugin - details on https://github.com/akka/akka-persistence-cassandra