Consistency Boundaries¶
One of the most powerful – and underused – tools in event-driven architecture is the concept of consistency boundaries.
When you design a system, you must decide:
Which parts need to be updated together – and which don't?
Understanding this boundary is the key to modeling aggregates, defining transactions, and managing complexity.
What Is a Consistency Boundary?¶
A consistency boundary defines the scope within which state changes must be consistent – either immediately or atomically.
Outside that boundary, consistency can be eventual.
In DDD terms, a consistency boundary typically aligns with an aggregate.
Example: The Library¶
Consider a city library.
- A
BookCopycan be borrowed or returned. - A
Membercan borrow multiple books – but only up to 5 at a time.
When someone borrows a book:
- You must ensure the copy is available.
- You must ensure the member hasn't exceeded the limit.
So what's the consistency boundary?
- If you need both checks to be atomic, you may choose to treat
BookCopyandMemberas one consistency boundary. - If you're okay with eventual consistency, you might only check one side in real time, and rely on validation or compensating actions for the other.
Dynamic Consistency Boundaries¶
Not all boundaries are fixed.
Some systems use dynamic consistency boundaries – boundaries that depend on runtime context.
Example:
- Returning a book might usually only touch the
Loan. - But if the loan is very overdue, it might trigger a penalty – involving the
Memberaccount.
In such cases, the consistency boundary grows temporarily.
You can handle this by:
- Choreographing events across multiple entities
- Using sagas or process managers to manage multi-step consistency
- Keeping each individual step within its own boundary
Why It Matters¶
Clear consistency boundaries help you:
- Avoid overengineering monolithic transactions
- Design better aggregates
- Know where to accept eventual consistency
- Split responsibilities cleanly across your system
When your boundaries are well-defined, the rest of your architecture becomes easier to understand, test, and evolve.
Next up: Return to the summary and review how all the pieces of event-driven architecture fit together.