Concept Architecture
Aggregate (Domain-Driven Design) in Health Economic Modelling
An aggregate, in Domain-Driven Design (DDD), groups the objects whose data must agree with each other, places them behind one root object and lets every change to the group pass through that root. The root is answerable for a set of rules that must hold whenever the group is saved, so the boundary is drawn around consistency and has nothing to do with summarising data. For a health economic model the natural candidate is a single model run, whose input values, transition matrix and cohort trace have to agree for its results to be trusted. The wiki's Domain Layer uses the idea to say which rules a model run must satisfy and which object enforces them.
Origin of the term and who uses it
Aggregate is a software design term and is new to health economics. Martin Fowler credits the 2003 book by Eric Evans that gave Domain-Driven Design its name with identifying the concept of aggregates. Evans's free reference booklet of 2015 lists aggregates among the building blocks of a model-driven design, beside entities, value objects, domain events, services, modules, repositories and factories.
Fowler's own entry describes a DDD aggregate as a cluster of domain objects that can be treated as a single unit, and gives a clinic visit as an example of the domain concepts aggregates represent. Vaughn Vernon's three-part essay Effective Aggregate Design of 2011 calls the pattern one of the least well understood parts of DDD tactical guidance. The wiki label matches the term these sources use, qualified because the wiki already has pages on the aggregate model and aggregate data meta-analysis, which use the word in its statistical sense of summary data. None of the health economics sources read for this page uses aggregate in the DDD sense.
The problem the pattern addresses
Evans starts from the difficulty of guaranteeing consistent changes in a model with complex associations. Objects can be blindsided by changes to other objects that are conceptually parts of them, and cautious database locking makes users interfere with each other for no gain. In his remedy, entities and value objects are clustered into aggregates with a boundary around each, and one entity is chosen as the root. Outside objects may hold references to the root only, and the properties and invariants of the aggregate as a whole are enforced by the root or by a designated framework mechanism.
The same boundary then governs transactions and distribution. Within it, consistency rules apply synchronously, and across boundaries updates are handled asynchronously. Evans ties two further patterns to the aggregate. Repositories give query access only to aggregate roots that need it, and factories create an entire aggregate as a piece while enforcing its invariants.
The aggregate as a consistency boundary
Vernon turns the pattern into four rules of thumb, and the first shapes the others. He defines an invariant as a business rule that must always be consistent, in the transactional sense of immediate and atomic, and concludes that an aggregate is synonymous with a transactional consistency boundary. A well designed aggregate can be changed in any way the business needs while its invariants stay consistent within one transaction, and a well designed bounded context changes only one aggregate instance per transaction.
His second rule is to design small aggregates, limited to the root entity and the minimum of attributes and value-typed properties that must stay consistent with one another. The third is to reference other aggregates by their identity rather than by holding the objects themselves. The fourth is to use eventual consistency outside the boundary, so a rule spanning two aggregates is met by a later update, typically triggered when one aggregate publishes a domain event that another part of the system handles in its own transaction. Vernon quotes Evans's 2003 book that any rule spanning aggregates will not be expected to be up to date at all times.
In Vernon's worked case, a product in a project planning tool was first modelled as one large aggregate holding all its backlog items, releases and sprints. When one user planned a backlog item and another scheduled a release at the same time, the second save failed, because both changes touched the same aggregate. Vernon traces the failure to false invariants, constraints the developers imposed that were not real business rules.
A model run as an aggregate
Health economic models already have a unit that matches the pattern closely. Alarid-Escudero and colleagues, describing the DARTH coding framework, build the decision model as a function that maps inputs to outputs, which calibration and probabilistic sensitivity analysis then call repeatedly with different parameter values. A model run is one such execution with one set of input values, and the wiki's domain model page already treats the Model Run as an aggregate root.
The following design is the wiki's illustration and has not been tested in practice. The Model Run is the root entity, identified by its own run identifier. Inside its boundary sit the parameter set, held as a value object that is replaced whole and never edited, the transition matrix built from it, the cohort trace and the run status. The model specification and the stored results lie outside. The run refers to the specification by identity, and each result set refers back by identity to the run that produced it. If named, versioned parameter sets are kept as entities elsewhere, the run can refer to the one it used by identity and still keep its own unchangeable copy of the values.
The root answers for the rules on everything inside, though a rule confined to one part, such as the row rule on the transition matrix, can also be checked by the matrix itself, held as a value object, when it is created. The cohort tutorial by Alarid-Escudero and colleagues requires each entry of the transition probability matrix to lie between 0 and 1 and each row to sum to one, and it checks every matrix in this way once all have been created. The wiki's planned Rules and Invariants records express the row rule with a tolerance of 0.000001. The TECH-VER verification checklist adds a black-box test that the numbers of patients across the health states should add up to the cohort size. Further rules, such as refusing a new parameter set once the run has started, follow from treating the run as one unit. Planned component pages on transition-matrix validation and cohort propagation are meant to define these operations, but they are not yet published.
Worked example with a three-state Markov cohort
The numbers in this example are illustrative. A Markov cohort model has the states Well, Sick and Dead, and 1,000 people start in Well. The Well row of the transition matrix is 0.85 for staying Well, 0.10 for falling Sick and 0.05 for dying. The Sick row is 0 for recovery, 0.80 for staying Sick and 0.20 for dying, and Dead is absorbing with a probability of 1 of staying there. Each cycle multiplies the state vector by the matrix.
where is the row vector of the number of people in each state at the start of cycle , is the same vector one cycle later and is the transition matrix, whose entry is the probability of moving from state to state in one cycle. Summing the new vector over its states shows why the row rule matters.
where is the number of states, here three, is the number of people in state at cycle and is the number in state one cycle later. When every row sum of equals one, the inner sum is one for each state and the cohort total stays the same in every cycle.
In cycle 1 the Well row gives 1000 × 0.85 = 850 people in Well, 1000 × 0.10 = 100 in Sick and 1000 × 0.05 = 50 in Dead, a total of 850 + 100 + 50 = 1000. In cycle 2 Well holds 850 × 0.85 = 722.5. Sick holds 850 × 0.10 + 100 × 0.80 = 165, and Dead holds 850 × 0.05 + 100 × 0.20 + 50 × 1 = 112.5. The total is 722.5 + 165 + 112.5 = 1000, so the TECH-VER test passes.
Suppose an analyst mistypes the Sick death probability as 0.25. The Sick row then sums to 0.80 + 0.25 = 1.05, which breaks the row rule by 0.05. Had the run gone ahead, Dead in cycle 2 would hold 850 × 0.05 + 100 × 0.25 + 50 × 1 = 117.5 and the total would be 722.5 + 165 + 117.5 = 1005, five extra people, equal to 5% of the 100 in Sick. Because the root checks the matrix before the run starts, the run is refused and no result set based on it can exist. The check catches this slip only because each entry in the row was typed separately. If the probability of staying Sick were calculated as one minus the death probability, the row would still sum to one and the mistyped 0.25 would pass, so the row rule guards against entries that disagree and does not show that each value is right. A probability stored after rounding as 0.2000004 gives a row sum of 1.0000004, an error of 0.0000004, which is within the tolerance of 0.000001 and is accepted.
The size of the boundary also matters. In a probabilistic analysis with 1,000 parameter sets, one aggregate for the whole analysis would make each of the 1,000 completed runs a change to the same instance, so two runs finishing at the same moment on parallel processors could collide, as in Vernon's planning case. With one aggregate per run, each of the 1,000 transactions touches its own instance. A running count of completed runs for the whole analysis is then updated afterwards from completion events, which is eventual consistency of the kind Vernon recommends.
How it differs from nearby ideas
The word aggregate means several things in health economics, and only the DDD sense concerns consistency. An aggregate model represents a population through summary-level parameters rather than individual patients, while aggregate data meta-analysis pools study-level summary results. Fowler adds that DDD aggregates are sometimes confused with collection classes such as lists and maps, and that the word in other settings, such as UML, does not refer to the same concept.
A bounded context marks where one model and its ubiquitous language apply, so it encloses many aggregates, and Vernon describes aggregates as being discovered within a bounded context. An entity is defined by its identity and a value object only by its attributes, and an aggregate groups them under one root entity. An invariant is the rule itself, and the aggregate is the boundary within which a transactional invariant is kept.
Where aggregates are misread in health economic work
DDD is a body of software design practice, and its use in health economics is at an early stage. Three misreadings are likely when the idea is carried across.
- Reading aggregate as aggregation. A cohort in a Markov model is aggregated in the statistical sense because it tracks group proportions rather than individuals, but that does not make it a DDD aggregate. The DDD question is which objects must change together to keep a rule true.
- Making the whole analysis one aggregate. Putting every scenario and every probabilistic run inside one boundary repeats Vernon's large-cluster mistake. Rules that span runs, such as a complete set of results for a report, are better handled by references by identity and later updates than by one large transaction.
- Expecting the boundary to verify the model. An aggregate only places responsibility for a rule. Evans asks for invariants of aggregates to be stated as assertions and, where the language cannot express them, written as automated unit tests. The rules still need writing down and testing, and no source read for this page evaluates the pattern in health economic modelling.
Sources
- Alarid-Escudero F, Krijkamp EM, Pechlivanoglou P, et al. A need for change! A coding framework for improving transparency in decision modeling. PharmacoEconomics. 2019;37(11):1329-1339. https://pmc.ncbi.nlm.nih.gov/articles/PMC6871515/
- Alarid-Escudero F, Krijkamp EM, Enns EA, et al. An introductory tutorial on cohort state-transition models in R using a cost-effectiveness analysis example. Medical Decision Making. 2023;43(1):3-20. https://pmc.ncbi.nlm.nih.gov/articles/PMC9742144/
- Büyükkaramikli NC, Rutten-van Mölken MPMH, Severens JL, Al M. TECH-VER: a verification checklist to reduce errors in models and improve their credibility. PharmacoEconomics. 2019;37(11):1391-1408. https://pmc.ncbi.nlm.nih.gov/articles/PMC6860463/
- Evans E. Domain-Driven Design Reference: Definitions and Pattern Summaries. Domain Language, Inc.; 2015. Licensed CC BY 4.0. https://www.domainlanguage.com/wp-content/uploads/2016/05/DDD_Reference_2015-03.pdf
- Fowler M. DDD_Aggregate. martinfowler.com bliki; 23 April 2013. https://martinfowler.com/bliki/DDD_Aggregate.html
- Fowler M. DomainDrivenDesign. martinfowler.com bliki; 22 April 2020. https://martinfowler.com/bliki/DomainDrivenDesign.html
- Vernon V. Effective Aggregate Design, Parts I to III. dddcommunity.org; 2011. Licensed CC BY-ND 3.0. https://www.dddcommunity.org/wp-content/uploads/files/pdf_articles/Vernon_2011_1.pdf
Related Concepts (2)
Library
Publications
4
Domain-Driven Design Reference: Definitions and Pattern Summaries — Evans E, 2015 (Domain Language)
Source listed in the Sources of the HealthEconomics.wiki Concept Architecture articles on Domain-Driven Design, Domain (Domain-Driven Design), Subdomain (Domain-Driven Design), Core Domain, Bounded Context, Ubiquitous Language, Domain Model, Context Map, Strategic Design, Domain Expert, Entity (Domain-Driven Design), Value Object, Aggregate (Domain-Driven Design), Invariant (Domain-Driven Design), Anticorruption Layer, Published Language, Domain Event, Domain Service, Shared Kernel and Open Host Service, where it is cited as a reference for these concepts.
DDD_Aggregate — Fowler M, 2013 (martinfowler.com bliki)
Source listed in the Sources of the HealthEconomics.wiki Concept Architecture article on Aggregate (Domain-Driven Design), where it is cited as a reference for that concept.
Web (Open Access)View source →Effective Aggregate Design, Parts I to III — Vernon V, Licensed CC BY-ND 3.0 ed., 2011 (dddcommunity.org)
Source listed in the Sources of the HealthEconomics.wiki Concept Architecture article on Aggregate (Domain-Driven Design), where it is cited as a reference for that concept.
Domain Driven Design — Fowler M, 2020 (martinfowler.com)
Source listed in the Sources of the HealthEconomics.wiki Concept Architecture articles on Domain-Driven Design, Domain (Domain-Driven Design), Strategic Design, Core Domain, Domain Model and Aggregate (Domain-Driven Design), where it is cited as a reference for these concepts.
Web (Open Access)View source →
Frequently Asked Questions (6)
What is Aggregate?
An aggregate in Domain-Driven Design is a cluster of objects changed as one unit through a single root, such as one run of a health economic model.
Source: Evans 2015
Where does the term Aggregate (Domain-Driven Design) come from?
Aggregate (Domain-Driven Design) is a term from software design and is new to health economics. Martin Fowler explains that Domain-Driven Design takes its name from a 2003 book by Eric Evans, which classified objects into entities, value objects and service objects and identified the concept of aggregates. Fowler adds that the core notions of the approach are conceptual and apply with any programming approach. The wiki adds the qualifier to the page name because its pages on the aggregate model and aggregate data meta-analysis use the word in its statistical sense of summary data.
Source: Fowler 2020
How does Aggregate (Domain-Driven Design) differ from an aggregate model in health economics?
Aggregate (Domain-Driven Design) names a cluster of entities and value objects inside a software model, with one entity chosen as the root and made responsible for enforcing the rules of the whole cluster. An aggregate model in health economics instead represents a population through summary-level parameters, such as average transition probabilities, rather than tracking individual patients. The first concerns which objects must change together to stay consistent, while the second concerns the level of detail at which a population is simulated. A Markov cohort model can therefore be an aggregate model without being a DDD aggregate.
Source: Evans 2015
Why is Aggregate (Domain-Driven Design) described as a consistency boundary?
Vaughn Vernon defines an invariant as a business rule that must always be consistent, in the transactional sense of immediate and atomic, and concludes that Aggregate (Domain-Driven Design) is synonymous with a transactional consistency boundary. Everything inside the boundary must satisfy its rules whenever a transaction commits, and as a rule of thumb each transaction changes only one aggregate instance. Rules that span several aggregates are met later through eventual consistency, often triggered by a domain event. For a health economic model this suggests checking each model run as one unit rather than locking a whole analysis.
Source: Vernon 2011
How could a model run be designed as an Aggregate (Domain-Driven Design)?
In the wiki's illustration, a model run is an Aggregate (Domain-Driven Design) whose root holds the parameter set, the transition matrix built from it, the cohort trace and the run status. The root refuses to start the run unless the matrix is valid. A tutorial on cohort state-transition models in R by Alarid-Escudero and colleagues states that every transition probability should lie between 0 and 1 and that each row of a correctly specified matrix must sum to one. A run whose rows break that rule never produces results, so no report can rest on a matrix that makes the total across all states, the dead included, drift from the starting cohort size.
Source: Alarid-Escudero et al. 2023
What are common mistakes when using Aggregate (Domain-Driven Design) in health economic modelling?
One mistake is to read Aggregate (Domain-Driven Design) as statistical aggregation, when the term concerns which objects must change together to keep a rule true. Another is to place a whole analysis, with every scenario and probabilistic run, inside one boundary, although the pattern draws boundaries around the objects whose rules must hold together. A third is to expect the boundary itself to verify the model. Evans asks for the invariants of aggregates to be stated as assertions and, where the programming language cannot express them, written as automated unit tests, so each rule still has to be written down and tested.
Source: Evans 2015
Trust Record
Verified by Dr Darrin Baines
British health economist
Professional identity: darrinbaines.org
Verification date: 17 Nov 2026
Content version: 1.0.1
Canonical Identity
- Term code
- HS-HP-DH-122
Stable URI · Machine-readable · Resolvable · CC BY 4.0
