Search code examples
transactionsdomain-driven-designaggregatecqrsaggregateroot

Multiple Aggregates Root INSTANCES per transaction


In DDD the Aggregate should represent the transactional boundary. A transaction that requires the involvement of more than one aggregate is often a sign that either the model should be refined, or the transactional requirements should be reviewed, or both.

Does it mean the transaction boundary is per aggregate root INSTANCE or per aggregate?

Say I have an aggregate root called "Node", within each "Node" I have a collection of "Fields (Value objects)". Each "Field" is of a Type, and can be of Type "Node". In my case, if it is of Type "Node", I will store the Id to the "Node" aggregate Root.

Node (AggregateRootID 1)
---> Field1 : String (John)
---> Field2 : String (Doe)
---> Field3 : Node (AggregateRootID 2)

Node (AggregateRootID 2)
--> Field1 : String (Jane)
--> Field2 : String (Doe)

If I have a transaction that updates both AggregateRoots Instances, is that valid?

Or does it mean if I have "Node" aggregate and "Element" aggregate that I cannot update both of them in one transaction?


Solution

  • I think an AR may be more about the consistency boundary than the transaction boundary.

    The fact that a transaction happens to fit nicely around an AR boundary is just coincidence.

    Since transactions are more of an application layer concern, if you end up with more than one AR in a transaction then it does not necessarily indicate a design issue.

    In fact, I would go so far as to say that in some 100% consistency requirement scenarios you may not even have a choice but to include all changes in one transaction.