nw-ddd-tactical
Tactical DDD
Implementation patterns within a bounded context. Tactical DDD answers: "How do we structure the domain model?"
Aggregates
An aggregate is a consistency boundary -- a cluster of domain objects that must be transactionally consistent.
Vernon's Four Design Rules
-
Model true invariants in consistency boundaries: Only include elements that MUST be consistent within the same transaction. If two entities don't share an invariant, they belong in separate aggregates.
-
Design small aggregates: ~70% of aggregates contain only a root entity with value-typed properties. Large aggregates create concurrency contention, scalability failures, and memory pressure.
-
Reference other aggregates by identity: Use
ProductIdnotProduct. Direct object references create accidental cross-aggregate transactions and prevent independent scaling. -
Use eventual consistency outside the boundary: Domain events communicate across aggregates. One transaction = one aggregate. If you need to update two aggregates "atomically," reconsider your boundaries.