Let’s say I have the following scenario. There is an UserActor. Apart from trivial properties like Id, FirstName, LastName, user internal state contains a CategoryId, which represents user adherence to specific Category. The category itself is a separate domain entity which has properties by its own. To perform the operation of assignment user to specific category I have to make sure that the specific category actually exists. What is the proper way of dealing with this kind of scenarios, which guarantee system consistency?
I am thinking about two solutions, but I am not sure which is worse than the other. :D
- Ignore rule “tell don’t ask”, and query CategoriesActor using Ask protocol to determine if category with specified Id exists or not?
- Spawn some sort of auxiliary actor (ValidatorActor) which perform all the necessary validations and reply with result to UserActor. In the meantime, UserActor will change its state to sth like “Waiting for Command Results” and will be stacking all incoming messages up until proper command validation results arrive.
The first solution denies everything I believe. The second does not scale too good in terms of class/actors proliferation. Moreover, if UserActor is persistent FSM I have no idea how to go back from this “waiting for command validation results” limbo. There is no Unbecome equivalent for FSMs :/.
I believe if you use Akka together with CQRS/ES approach you should deal with this kind of issues. How did you address them? I have read a few books about Akka and haven’t found any opinionated approach. It’s strange because in my opinion, it is such a fundamental use case.
I would really appreciate any hints.