Aggregate root

What is an aggregate root?

An aggregate is a cluster of domain objects that is treated as a single unit.

Any references from outside the aggregate should only go to the aggregate root so that root can ensure the integrity of the aggregate as a whole.

As an aggregate root is responsible for maintaining integrity of the whole, it is the primary responsible for deciding if a command can be executed on the aggregate or not.

This decission will be recorded as an event on an event stream and any internal state is updated in response to the recorded event.

When to use it?

Use this pattern every time a user, or an automated part of the system, wants to make a change.

Encapsulate the intent into a command and send it to the aggregate root, so that it can take a decission on how to respond to the intent.

Want to give it a try?

Check out the sample we made available for you on github.