Aggregate (DDD)
A cluster of objects changed as one unit, with a single root that enforces the business rules and marks the boundary of one transaction.
An order with its lines is an aggregate: you change lines only through the order, and the order checks that the total stays within the credit limit. One transaction changes one aggregate; other aggregates are referenced by id and updated through events. Aggregates that are too large cause lock contention; too small, and the rules leak into services.
Related terms
- DDD (domain-driven design): Designing software around the business’s own language and rules, with the code split where that language changes meaning.
- Transactional outbox: Saving an event to an outbox table in the same database transaction as the change itself, then publishing it to the broker separately.
- Message ordering: Whether a queue delivers messages in the order they were sent; usually guaranteed only per key or partition, if at all.
- Value object: A small immutable object defined only by its values, like money or a date range; two with the same values are the same thing.
- Domain event: A fact the business cares about, named in the past tense (“visit booked”), that other parts of the system can react to without being called directly.
- Entity (DDD): A domain object with its own identity that stays the same while its data changes, such as a patient, an order or a doctor’s profile.
- Business invariant: A business rule that must be true at all times, such as “a slot cannot be booked twice”, which the model enforces on every change.
- Repository pattern: An object that looks like an in-memory collection of aggregates (add, find by ID, remove) and hides how they are stored.
