mercredi 22 mars 2023

Akka, DDD and hierarchy of actors as aggregates

I know Akka and the actor model works well in a DDD approach. However, I do have one question about the hierarchy.

Imagine that I have a system where we can send messages to users. I may have one UserActor and a MessageActor.

+-----------+      +--------------+
| UserActor |      | MessageActor | 
|-----------|      |--------------|
| + id      |      | + id         |
+-----------+      | + userId     |
                   +--------------+

At some time, we may want to disable an user, and we do not want this user to accept any new messages.

It seems to be useful to have the UserActor receiving the CreateMessage and Disable commands. So that a disabled user can reject new messages without having to maintain that state somewhere else.

+------------+      +--------------+
| UserActor  |      | MessageActor | 
|------------|      |--------------|
| + id       |   /->| + id         |
| + messages |--/   +--------------+
+------------+                       

Is that a common usage or is it better to limit the number of child actors and use other mechanism to maintain the constraints ?

Thanks

Aucun commentaire:

Enregistrer un commentaire