I have an akka-http api that, upon receiving requests, sends messages to my Cluster via the cluster sharding region. The API layer doesn’t know the ActorRefs of the actors in question, just the string identifiers.
region ! AddTarget(sourceId, targetId)
So Cluster Sharding works by looking up or creating the appropriate actor identified by “sourceId”, passing “targetId” as an additional parameter.
Each actor can have many targets - they’ll all be talking to each other.
From within the source actor, I’m faced with the choice of storing those targets as List[String] or List[ActorRef].
If I stick with List[String], I can use context.parent to send the message to the targets, through the region.
If I use List[ActorRef] instead (presumably by doing a one time Identify exchange so I can get the ActorRef from the response’s sender()), I’d be able to skip the region lookup on all ensuing communications.
Is one a best practice, or clearly better than the other?