In domain-driven design (DDD), a consistency boundary is a boundary within the domain that defines the scope within which changes to the domain objects must maintain consistency and integrity.
A consistency boundary defines a group of domain objects, called an aggregate, that are treated as a single unit. All changes to the objects within the aggregate must be made in a way that maintains the consistency and integrity of the data it encapsulates. This means that the state of the aggregate must be consistent before and after the changes (in other words – strongly consistent).
For example, in an e-commerce domain, an aggregate might be an order, which consists of an order header object and one or more order line item objects. The consistency boundary of the order aggregate would ensure that the order total is correct, and that the order is in a valid state before and after any changes are made.
A consistency boundary also helps to ensure that the domain objects within the aggregate are protected from external changes and that they can be accessed and modified only through the aggregate root.
In DDD, consistency boundaries are used to model the consistency rules within the domain and to ensure that the state of the domain is always consistent. They are also used to control access to the child objects, and to provide a way to perform operations that involve multiple objects in the aggregate.
It’s important to note that consistency boundary is not just limited to the data consistency but also to the business rules consistency. It’s a way to ensure that the domain is consistent and that the integrity of the domain is maintained.