2023-03-08 21:39:52

Customer Aggregate

Customer Aggregate Root
_a_m_p_;_darr; 1 .. n
Address

Address is part of the Customer.

Product Aggregate

Product Aggregate Root
_a_m_p_;_darr; 1 .. n
Component

Component is part of the Product.

Every aggregate must have an aggregate root.

Aggregate

A transactional graph of objects.

Aggregate Root

The entry point of an aggregate ensures the integrity of the entire graph.

  • Aggregate should enforce data consistency within the aggregate.
  • Aggregate should ensure that it is valid.
  • Data changes within an aggregate should follow ACID:
    • Atomic
    • Consistent
    • Isolated
    • Durable
  • Deleting the Root should delete the entire aggregate.

An aggregate is a cluster of associated objects that we treat as a unit for the purpose of data changes.

Eric Evans

Handling Relationships that Span Aggregates

External objects should interact with only the aggregate root.

Customer Aggregate

Customer Aggregate Root
_a_m_p_;_darr; 1 .. n
Address

Address is part of the Customer.

_a_m_p_;_rlarr;

Product Aggregate

Product Aggregate Root
_a_m_p_;_darr; 1 .. n
Component

Component is part of the Product.

  • Aggregate root is responsible for maintaining the rules of the aggregate.

Aggregate Tips

Aggregates are not always the answer
Aggregates can connect only by the root
Don’t overlook using FKs for non-root entities
Too many FKs to non-root entities may suggest a problem
“Aggregates of one” are acceptable
“Rule of Cascading Deletes”
Copyright © 2025 delaney. All rights reserved.