DDD: final consistency and 1 to n relationships

In my domain, I have aggregates of products and orders. Orders refer to products. This ratio is from 1 to n, so the product has many orders and orders belonging to the Product. When a product is terminated, a ProductDiscontinued event is thrown, and all Orders belonging to this Product must be canceled. So, there is an adapter that receives the ProductDiscontinued event via RabbitMQ. Then the adapter canceled the application service orders. How can I ensure that one order is canceled in one transaction? Should the adapter go through all orders for a discontinued product and call the application service for each individual order? Should I just ignore that I change several aggregates in one transaction and call the application service only once with a list of all affected OrderId? Is there a better solution?

+4
source share
1 answer

From the point of view of DDD, aggregation is the boundary of a transaction. The transaction must not exceed the Unit. This rule exists in order to force a person to design aggregates correctly so as not to depend on several aggregates modified in the same transaction.

However, you have already developed your Aggregates, bearing this in mind (from what I see).

Should the adapter redirect all orders for a discontinued product and call the application service for each individual order?

This is a normal way to do things.

Should I just ignore that I am changing more than one aggregate in one transaction and calling the application service only once with a list of all affected OrderId?

, , , - ( , , , ).

+1

Source: https://habr.com/ru/post/1692031/


All Articles