0
votes

In this moment I have this actor session management implementation running in only one node:

1) I have a SessionManager actor that handles all sessions

2) The SessionManagerActor receives two messages: CreateSesion(id) and ValidateSesion(id)

3) When the SessionManagerActor receives CreateSesion(id) message, it creates a SessionActor using actorFor method like so:

context.actorOf(Props(new SesionActor(expirationTime)), id)

4) When the SessionManagerActor receives ValidateSesion(id) message it looks for an existing SessionActor and evaluates if exists using resolveOne method like so:

context.actorSelection("akka://system/user/sessionManager/" + id).resolveOne()


With that logic works nice but I need to implement the same behavior in multiple nodes (cluster)

My question is, which method is recommended to implement that session management behavior so that it works in one or múltiple nodes?

I've read akka documentation and it provides akka-remote, akka-cluster, akka-cluster-sharding, akka-cluster-singleton, akka-distributed-publish-subscribe-cluster but I'm not sure about which one is the appropriate and the simplest way to do it. (Note that SessionActors are stateless and I need to locate them anywhere in the cluster.)

1

1 Answers

1
votes

Since you have a protocol where you validate whether a session already exists or not and have a time-to-live on the session, this is technically not completely stateless. You probably would not, for example, want to lose existing sessions and spin them up again arbitrarily, and you probably don't want to have multiple sessions created per id.

Therefore, I would look at the cluster sharding mechanism, possibly in combination with akka-persistence to persist the expiration state of the session.

This will give you a fault tolerant set up with rebalancing when nodes go down or new nodes come up.

The activator template akka cluster sharding scala may be helpful for example code.