Architectureaggregate rootconsistency boundary

Aggregate

Definition

In domain-driven design, an aggregate is a group of entities and value objects treated as one consistency boundary; all changes go through its aggregate root, and one transaction changes one aggregate.

In practice

The root enforces invariants such as "at most 50 lines" or "total within the credit limit", and an optimistic concurrency token on the aggregate stops two concurrent edits from both winning. Other aggregates are referenced by id only, and rules that span aggregates are handled with domain events and eventual consistency.

An aggregate is also a unit of locking, so big ones serialise unrelated work: a Customer aggregate holding every order makes all of that customer's writes queue behind each other. Keep aggregates as small as the true invariants allow. The term is unrelated to SQL aggregate functions.

Example

An Order aggregate contains its OrderLines; order.AddLine(sku, qty) checks the 50-line limit and the save fails with a concurrency conflict if the row version changed meanwhile.