liveBook · Manning

Aggregate

As explained in Collaborative Software Design: How to facilitate domain modeling decisions

A consistency boundary is a boundary within which related state must satisfy business invariants as a single consistent unit.

An aggregate is a consistency boundary around related domain objects. It protects business invariants by applying constraints within one boundary and one transaction, preventing invalid states. section 12.3.2 section 12.7

Design the boundary around the rules that must hold together. In seat allocation, Seat, Row, and ScheduledMovieSeating can form an aggregate whose root manages changes so one seat cannot be allocated to multiple tickets. section 12.3.2 section 12.5

Use these design prompts when moving from collaborative modeling toward implementation:

  • Identify the business invariants that must never be violated. section 12.3.2
  • Place the related domain objects inside one consistency boundary when the invariant must be enforced atomically. section 12.3.2
  • Translate discovered constraints into aggregate methods and refine them through deeper business discussion. section 12.7

Preventing duplicate seat allocation

A scheduled movie must not reserve one seat for multiple tickets. An aggregate containing Seat, Row, and ScheduledMovieSeating can enforce that rule through ScheduledMovieSeating as its aggregate root. section 12.3.2

Figure 12.14 Our EventStorm is divided into consistency boundaries (rectangles). Most of the events reside within the Seat allocations context. Two commands and events are from different bounded contexts (rounded corners): Price Calculation and Payments.

Use the consistency-boundary map to distinguish the Seat Allocations aggregate area from Price Calculation and Payments in other bounded contexts. section 12.3.2

How Collaborative Software Design: How to facilitate domain modeling decisions covers it

How deep it goes
Explains boundaries, transactions, aggregate roots, and invariant enforcement, then stops short of a complete implementation.
Examples
Uses seat allocation, scheduled movies, tickets, rows, and a simplified ScheduledMovie aggregate to illustrate invariant enforcement.
What it assumes
Assumes collaborative modeling and bounded contexts, while connecting EventStorm constraints to implementation decisions.
What you can do after
Builds aggregate boundaries and methods from modeled constraints while keeping related domain objects internally consistent.
How it connects
Connects aggregates with bounded contexts, domain objects, aggregate roots, business invariants, transactions, commands, and events.

Also explained in

Compare how 3 books explain aggregate →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Collaborative Software Design: How to facilitate domain modeling decisions. The section links point to the parts of the book it draws on.