0
votes

I am just getting into DDD, CQRS and Event Sourcing and am having trouble with the concept of related aggregates and how much data can be shared between the two when publishing events that involve both. My issue... I have a customer aggregate that has a collection of address aggregates and an event that is published when an address is added to the customer. Both address and customer aggregates maintain relationships with phone numbers/sales people and contacts.

My understanding is I can only reference an aggregate from another aggregate by id. Am I allowed to pass more data about the address than just the address aggregate id to the customer when the address is added as long as I only reference the address id from the customer aggregate?

I think that I need extra data so when I publish the event I can eventually persist that data/relationship to the read side into a customer addresses table.

1

1 Answers

2
votes

When you find yourself trying to access data that belongs to another aggregate, you should double check to make sure that your aggregate boundaries are aligned with your needs.

That said, it is reasonable to copy information from one aggregate to another. For instance, in a shipping domain, we're probably going to copy a shipping address into each shipment, but we probably don't manage the lifetime of the shipping address within the shipment entity itself.

So we tend to pay attention to which entities hold the authoritative information, and which are using stale immutable copies. See Pat Helland Data on the Outside....