I have a Akka application that I run as a Web application using Play Framework. When I start this application, I create a set of Actors ad these actors have state. These actors respond to external messages and mutate the state (I mutate the state using the context.become(...) mechanism).
I now want to run multiple instances of this Web application so that I can have resiliency. But the problem with this is that the web application exposes a WebSocket endpoint to which a Front end application connects. I then stream the state of the Actor instance every 4 seconds via the WebSocket endpoint to the Front end application.
I have few questions here:
How can I run a couple more instances of my Play Framework web application, keeping in mind that I have Stateful actors! I want to make sure that if one of the instance goes down, the Stateful actor in that instance is resurrected with the state as it was just before it went down. Would Akka Cluster Sharding be the way to go?
Say I have 10000 of these Stateful actors in my application, how can I leverage Akka Cluster Sharding such that not all of these 10000 actors are running in the same node? I mean how can I make the first 5000 actors run on node1 and the next 5000 run on node2? Right now what I do with the single instance is that when I start my application, I read the database and I use the data to start one actor instance per database row.
How does ask pattern works with cluster sharding? Any messages that I send to the Shard Region will be routed to the corresponding Actor instance, but what about asking for messages from a specific actor? Will it also work the same way? I ask for a message from an Actor, I send my ask request to the Shard Region and this shard region forwards this message to the corresponding Actor? Is this correct?
Any suggestions?