الانتقال إلى المحتوى
Software ArchitectureDDD· 7 دقائق للقراءة

An Aggregate Is a Consistency Boundary, Not a Big Object Graph

Put inside an aggregate only what must be consistent when a transaction commits. Reference everything else by identity, and let it catch up asynchronously.

ReadIn

مقال كل يوم يفرق معاك

21 نوفمبر 2026
  • كاتب موثّق
محتويات المقال

Checkout gets slower every month. Placing an order loads the Customer aggregate: profile, addresses and every order the customer ever placed, with their lines. For a loyal customer that's thousands of objects in memory to add one order. Then the second complaint arrives: when support updates a customer's phone number while she's checking out, one of the two saves fails with a version conflict. Nothing about a phone number affects an order, yet both changes go through the same root, so they collide.

The common misconception

The belief: an aggregate is a root entity with everything related to it hanging underneath, so the whole object graph can be loaded, navigated and saved together. A customer has orders, so orders go inside the customer.

It's a reasonable reading of the definitions. Fowler describes an as "a cluster of domain objects that can be treated as a single unit", and says "you request to load or save whole aggregates." ORMs make navigation properties easy, and customer.Orders reads naturally. Vernon's essay opens with exactly this question, "Is an aggregate just a way to cluster a graph of closely related objects under a common parent?", and its fictional team falls into the trap by putting weight on the words "Products have".

The half-truth: an aggregate is a cluster with one root, loaded and saved as a whole. But what decides membership is which rules must hold together in one transaction, not which objects happen to be related.

What actually happens

Aggregates exist to protect invariants

Evans's DDD Reference starts the pattern from a problem: "It is difficult to guarantee the consistency of changes to objects in a model with complex associations." The answer is to cluster objects, choose a root, allow outside references to the root only, and "Define properties and invariants for the aggregate as a whole". Then: "Use the same aggregate boundaries to govern transactions and distribution." Fowler is just as direct: "Transactions should not cross aggregate boundaries." Vernon sums it up: "aggregate is synonymous with transactional consistency boundary", and aggregates "are chiefly about consistency boundaries and not driven by a desire to design object graphs."

Big aggregates fail in two ways

The first is contention. In Vernon's example, Bill plans a backlog item and Joe schedules a release on the same product. The aggregates use , so Joe's save fails: the product's version changed under him. Vernon's verdict: "Nothing about planning a new backlog item should logically interfere with scheduling a new release!" The big cluster was built on "false invariants", constraints the developers invented rather than real business rules. Evans warns that cautious locking makes users "interfere pointlessly with each other", and Microsoft's Azure guide says combining aggregates forces "unrelated updates to compete for the same locks."

The second is load. Vernon describes "thousands of backlog items" loaded into memory "just to add one new element to the already large collection". Collections that start empty grow for years.

Small, by identity, eventually consistent

Vernon's rules, which Microsoft's guide repeats: design small aggregates, containing "only the data that must remain consistent within a single transaction"; reference other aggregates by identity, the way a delivery stores a drone's ID instead of the drone; and use outside the boundary. Evans says the same: "Within an aggregate boundary, apply consistency rules synchronously. Across boundaries, handle updates asynchronously." A raised by one aggregate is the usual way to update another later.

Small can mean very small. Microsoft notes that an aggregate can be a single entity: "What makes it an aggregate is the transactional boundary." Vernon reports one project where about 70% of aggregates were just a root entity with value-typed properties, while stressing that this ratio won't hold for every domain.

The fix: one aggregate per consistency rule

C#
// "A customer has orders", so the aggregate holds all of thempublic sealed class Customer{    public CustomerId Id { get; init; }    public string Phone { get; private set; } = "";    public List<Address> Addresses { get; } = [];    public List<Order> Orders { get; } = []; // every order, for years    public int Version { get; private set; } // checked on every save    public void PlaceOrder(Order order) { Orders.Add(order); Version++; }    public void ChangePhone(string phone) { Phone = phone; Version++; }}// Checkout loads years of orders to add one, and a phone change// at the same moment makes one of the two saves fail

Placing an order now creates one Order and saves it, without loading the customer at all. A phone change and a checkout touch different aggregates, so they no longer collide. Rules that span both, such as awarding loyalty points, react to an order-placed event in their own transaction. Screens that need a customer with their order history get it from a query, not by loading aggregates, and Vernon suggests CQRS when those queries get expensive.

MythReality
An aggregate holds everything related to its rootIt holds what must be consistent within one transaction
Bigger aggregates are saferThey cause false conflicts and load thousands of objects to change one
Aggregates should reference each other as objectsReference other aggregates by identity, like a delivery storing a drone's ID
One request should update all related data atomicallyEvans: synchronous inside a boundary, asynchronous across boundaries
An aggregate needs child entitiesIt can be a single entity; the transactional boundary is what makes it one

How to apply it in your project

  1. List the true invariantsFor your largest aggregate, write down the rules that must hold every time a change commits. Ask domain experts which ones are real and which a developer invented.
  2. Draw a boundary around each rule's dataKeep together only the data one rule needs to check. Everything else becomes its own aggregate, often a single entity.
  3. Replace object references with IDsStore CustomerId, not Customer. Let the application service load what a command needs, and serve screens from queries instead of aggregate graphs.
  4. Move cross-aggregate rules to eventsWhen one change must trigger another, raise a domain event and handle it in a separate transaction, and agree with the business how long the delay may be.

Key takeaways

  • An aggregate is a transactional consistency boundary, not a container for everything related.
  • Only data that must be consistent at commit time belongs inside; many aggregates are a single entity.
  • Big aggregates cause false conflicts between unrelated edits and load far more than each change needs.
  • Reference other aggregates by identity, and keep them in step with domain events and eventual consistency.
  • Ask whose job consistency is: the current user's job means one transaction, anyone else's can wait.

📚 المصادر

  1. DDD_Aggregate — Martin Fowler, bliki (2013)
  2. Domain-Driven Design Reference — Eric Evans, Domain Language (2015)
  3. Effective Aggregate Design, Part I: Modeling a Single Aggregate — Vaughn Vernon (2011)
  4. Effective Aggregate Design, Part II: Making Aggregates Work Together — Vaughn Vernon (2011)
  5. Use tactical DDD to design microservices — Azure Architecture Center, Microsoft Learn

التعليقات (0)