Search code examples
domain-driven-designaggregateroot

Aggreate Root, Aggregates, Entities, Value Objects


I'm struggling with some implementation details when looking at the terms mentioned in the title above.

Can someone tell me whether my interpretation is right?

For reference I look at a CRM Domain

As a AggregateRoot I could see a Customer.

It may have Entities like Address which contains street, postal code and so on.

Now there is something like Contact and Activity this should be at least aggregates. Right? Now if the Contacts and Activities would have complex business logic. For example, "Every time a contact of the type order is created, the order workflow should be started"

Would then Contact need to be an Aggregate root? What may be implementation implications that could result from this?

Further more when looking and Event Sourcing, Would each Aggregate have its own Stream? In this scenario A Customer could have thousands of activities.

It would be great if someone could guide em in which part my understanding is right and which I differ form the common interpretation.


Solution

  • What do you mean by “at least aggregates”?

    An aggregate is a set of one or more connected entities. The aggregate can only be accessed from its root entity, also called the aggregate root. The aggregate defines the transactional boundaries for the entities which must be preserved at all time. Jimmy Bogard has a good explanation of aggregates here.

    When using event sourcing each aggregate should have its own stream. The stream is used to construct the aggregates and there is no reason to let several aggregates use the same stream.

    You should try to keep your aggregates small. If you expect your customer object to have thousands of activities then you should look at if it is possible to design the activities as a separate aggregate, just as long as its boundaries ensures that you do not leave the system in an invalid state.