DDD Events Between Aggregates Example

I have two aggregates

item and price adjustment.

A price adjustment will contain an item adjustment which will say, for a specific item, raise it by x percent (e.g. 10%)

my item has a list price which is what needs to be updated/adjusted.

so when the price adjustment is processed, it is going to find that item and needs to adjust that item's list price by the percentage specific. When the adjustment is complete, the item adjustment in the price adjustment needs to be marked as complete

My question is how is this updating of the list price and marking of the item adjustment being performed composed into events?

What is the correct way for me to both update the list price and mark the item adjustment as completed following events?

Is this a correct solution?:

  • call function on the item such as AdjustListPrice and pass in the price adjustment information such as the id and percentage to be adjusted by.
  • Then raise an event such as ItemListPriceAdjusted have the price adjustment listen so that it can mark the adjustment as complete and raise another event such as itemPriceadjustmentCompleted

if this is the correct way, should the new calculated list price be added to the ItemListPriceAdjusted price, or should just the adjustment percentage be added and this is then calculated when it is applied/read from the aggregate?


1 answer

  • answered 2020-07-22 11:24 iTollu

    We are talking DDD here. So the first question I'd ask is what's happening in the business that you want to reflect with code.

    It is highly unlikely that a business would decide to "adjust prices" by 10% on the whole assortment. That has something to deal with the pricing strategy. Which is individual to a product or a category of products. So, I'd start with asking the business first.

    Next, if in the underlying business you have some dedicated people or departments to deal with the pricing, that would give you the context boundary. Most likely pricing is a separate domain from inventory (listing the products). Most likely there is some base price, the prime cost of a product. Then there are some additional costs, some margin to it which will form the profit. So, by "adjusting" a price - what are you going to achieve? Does it mean that a prime cost changed? Or a margin changed? Or some marketing campaign ended? Figure it out - and you'll get the answer to your question. You'll be able to derive the event name from it.

    To sum up: store/fire/raise/dispatch an event that is relevant to THE business.