An aggregate is a tactical pattern of domain-driven design (DDD): it defines where the transaction boundary lies, what may be changed through the public interface and what must remain consistent at all times. Eric Evans introduced the concept in his 2003 book “Domain-Driven Design”.
The structure of an aggregate
- The root is an entity with a globally unique identifier; it is the only thing visible from outside.
- Inner entities and value objects live only inside the boundary and obey the root.
- References from other aggregates point only to the root, most often by identifier.
- Invariants that must hold at all times are kept within a single aggregate.
Example: an order
In an online shop the aggregate is an order: the root is Order, and inside are the OrderLine items and the total. The rule “the sum of the items equals the order total” is an invariant, so it is checked inside: outside code does not edit the items directly but calls order.add_item(...).
class Order: def add_item(self, product_id: str, qty: int, price: int) -> None: self.lines.append(OrderLine(product_id, qty, price)) self.total = sum(line.amount for line in self.lines) # the invariant Rules around aggregates
One outside request changes one aggregate; the changes are saved in a single transaction, so the aggregate boundary is also the consistency boundary. When data from a neighbouring aggregate is needed, its root is called or the data is read by identifier; the aggregate reports changes with an event — a domain event. Vernon formulated the rule “one transaction updates one aggregate” in his essay “Effective Aggregate Design”.
Sources
the term is written from these pagesVerified 8 Nov