MessageHandler MH Sign Up

Aggregate root

What is an aggregate root?

An Aggregate Root is the root of an aggregate.

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 a specific entry point to the aggregate, the 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.

These decissions can be recorded as an event on an event stream, while any internal state of the aggregate can be derived from the recorded events.

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 quickstart for a quick example.

Or get started with the learning path, where you'll build an Aggregate Root yourself in lesson 3.

QUICKSTART LEARNING PATH