· 3 min read · updated
Mastering Transactions: The Power of Aggregates in DDD
Series: Domain-Driven Design (DDD) Series · part 9
- 1. What Domain-Driven Design Is (DDD series part 1)
- 2. Benefits of using DDD (DDD series part 2)
- 3. Who should consider using DDD? (DDD series part 3)
- 4. Domain Model (DDD series part 4)
- 5. Bounded Context (DDD series part 5)
- 6. Value object (DDD series part 6)
- 7. Entity (DDD series part 7)
- 8. Services (DDD series part 8)
- 9. Mastering Transactions: The Power of Aggregates in DDD
- 10. Domain Events in DDD (DDD series part 10)
- 11. Alternatives to Domain-Driven Design, and When to Use Them
As a software architect, it is important to understand the key concepts and patterns used in Domain-Driven Design (DDD). One of the most important of these concepts is the Aggregate.

Photo by Luca Bravo on Unsplash
An Aggregate is a cluster of related objects that are treated as a single unit for data changes. It defines a boundary around a set of objects and a root entity and provides a way to enforce transactional consistency and isolate the persistence of the objects from the rest of the application.
Benefits#
- One of the key benefits of using Aggregates is that they provide a way to enforce transactional consistency. By defining a boundary around a set of objects, an Aggregate ensures that all changes to the objects within that boundary are atomic and consistent. This means that if any part of a transaction fails, the entire transaction is rolled back, ensuring that the system remains consistent.
- Another benefit of using Aggregates is that they provide a way to isolate the persistence of the objects from the rest of the application. By encapsulating the persistence of the objects within the Aggregate, the rest of the application can interact with the objects without having to worry about the underlying persistence implementation. This makes it easier to change the persistence implementation without affecting the rest of the application, improving the maintainability of the system.
It is important to note that Aggregates should be kept small and focused. Large Aggregates can make it difficult to manage the transactional consistency of the objects and can make it more difficult to change the persistence implementation. Therefore, it is recommended that Aggregates be kept small, with a well-defined boundary, and with a clear and focused responsibility.
Examples#
Aggregates are a key concept in Domain-Driven Design (DDD) and provide a way to enforce transactional consistency and isolate the persistence of objects from the rest of the application. Examples of Aggregates in the real world include:
An e-commerce system#
In an e-commerce system, an Aggregate might consist of an Order, the Order Items, and the Customer. This Aggregate defines a boundary around these objects and ensures that changes to these objects are atomic and consistent.
A banking system#
In a banking system, an Aggregate might consist of an Account, the Account Transactions, and the Customer. This Aggregate defines a boundary around these objects and ensures that changes to these objects are atomic and consistent.
A healthcare system#
In a healthcare system, an Aggregate might consist of a Patient, the Patient’s Medical History, and the Patient’s Prescriptions. This Aggregate defines a boundary around these objects and ensures that changes to these objects are atomic and consistent.
These are just a few examples of Aggregates in the real world. The specific Aggregates that are used in a system will depend on the domain being modeled and the requirements of the system. However, the key idea behind Aggregates is to define a boundary around a set of related objects and to ensure that changes to these objects are atomic and consistent.
In conclusion#
Aggregates are a key concept in Domain-Driven Design and provide a way to enforce transactional consistency and isolate the persistence of objects from the rest of the application. By using Aggregates, organizations can ensure that their software systems are well-designed, maintainable, and easy to understand. As a software architect, it is essential to understand the benefits of using Aggregates and to ensure that they are used appropriately in the design of software systems.
Previous parts#
Value object (DDD series part 6)
Bounded Context (DDD series part 5)
Domain Model (DDD series part 4)
Who should consider using DDD? (DDD series part 3)
Benefits of using DDD (DDD series part 2)
Unlocking the Power of Domain Driven Design in Software Development (DDD series part 1)
$ related posts
15 min readNEW
The Read Side Does Not Go Through the Aggregate
CQRS read models in Symfony 8: a read port the domain does not own, a query bus that returns a value, and when a projection table earns its place. Part 3.
DDD, CQRS and Hexagonal Architecture in Symfony 8 · part 3#cqrs#ddd#hexagonal-architecture#symfony#php#postgresql#doctrine18 min readNEW
The Application Layer, the Transaction, and a Working API
Application layer in Symfony 8: use cases on a Messenger command bus, the transaction boundary in config, optimistic locking and RFC 9457 errors. Part 2.
DDD, CQRS and Hexagonal Architecture in Symfony 8 · part 2#ddd#hexagonal-architecture#symfony#php#cqrs#messenger#software-architecture15 min readNEW
The Domain Model, and the Only Rule That Matters
DDD domain model in PHP 8.5 and Symfony 8: keep the container out of the domain, and choose Doctrine ORM or DBAL with the costs on the table. Series part 1.
DDD, CQRS and Hexagonal Architecture in Symfony 8 · part 1#ddd#hexagonal-architecture#symfony#php#doctrine#software-architecture