Please give me some advise about: Akka Sharding & Akka Persistence

Please give me some advise? (Akka Sharding & Akka Persistence)

Hi all,
I’m building a service for mobile Game using Akka, WebSocket like this

So in this cluster i have

  • WebSocketActor
  • This actor create when device of user connect to service via WebSocket (1 user maybe have many devices)
  • UserActor
  • UserActor will be create in UserShard when WebSocket tell first message to UserActor with userId
  • When UserActor receive mesasge from WebSocketActor will keep ActorRef of this WebSocketActor

Example

  • Node 1:
    • WebSocketActor1, WebSocketActor2
  • Node 2:
    • UserActor1
  • Node 3:
    • UserActor2

So if i kill Node 3 => UserActor2 will lost connection with WebSocketActor2
Then i want to use Akka Persistence to store state of UserActor and recover when it restart on another node

Please tell me this solution good or not?
If good should i use kind of Akka Persistence (some choice: https://index.scala-lang.org/search?topics=akka-persistence&q=*&page=1)

  1. akka/akka-persistence-cassandra
  2. safety-data/akka-persistence-redis
  3. dnvriend/akka-persistence-inmemory (https://github.com/dnvriend/akka-persistence-inmemory)

It’s a good design. One small adjustment. Don’t send messages directly to the ActorRef of the UserActor, because that ref will be obsolete when that shard is rebalanced (new nodes might join cluster) or when that node crashes or is removed. Instead, send all such messages via sharding.

Regarding persistence plugin, my top recommendation would be akka-persistence-cassandra, followed by akka-persistence-jdbc. There are many other good alternatives if you have specific preference of database.