Aggregates

Learn what aggregates are and about their importance in the DDD world.

It might be necessary to create a huge number of entities and value objects and facilitate interactions between them, when we deal with a complex bounded context. These conditions may lead to the creation of a big ball of mud. As was explained before, this is an anti-pattern where interactions among objects are unmanageable. It can be described as a spaghetti code.

A big ball of mud implementation tends to grow out of control and is difficult to maintain over time. DDD understands this problem and solves it through the definition of a tactical pattern called aggregate.

What is an aggregate?

An aggregate object is a cluster of entities and value objects that are treated as a single unit from the domain and data perspective. This object acts as a load balancer for accessing a set of nodes. This means that an aggregate is the only access point for external objects. As the image below shows, an aggregate has clear bounds and the artifacts inside it cannot interact with the outside world:

Get hands-on with 1400+ tech skills courses.