liveBook · Manning

Business invariant

As explained in Collaborative Software Design: How to facilitate domain modeling decisions

A business invariant is a condition that must remain true for a domain model to represent a valid business state.

A business invariant is a condition that must remain true for a domain model to represent a valid business state. Preserving it prevents domain objects from becoming inconsistent. section 12.3.2

One seat per ticket

A cinema must prevent one seat from being allocated to multiple tickets. Placing Seat, Row, and ScheduledMovieSeating inside one aggregate lets ScheduledMovieSeating enforce the invariant during a single transaction. section 12.3.2

Use invariants to guide modeling decisions:

  • Identify the rule that must never be violated. section 12.3.2
  • Keep the information and constraints needed to enforce the rule within one consistency boundary. section 12.3.2 section 12.5
  • Apply the constraints in one transaction so related domain objects remain correct together. section 12.3.2
Figure 12.14 Our EventStorm is divided into consistency boundaries (rectangles). Most of the events reside within the Seat allocations context. Two commands and events are from different bounded contexts (rounded corners): Price Calculation and Payments.

Use the consistency-boundary diagram to distinguish the aggregate that protects an invariant from neighboring bounded contexts such as Price Calculation and Payments. section 12.3.2

How Collaborative Software Design: How to facilitate domain modeling decisions covers it

How deep it goes
Explains definition, transaction scope, and aggregate enforcement, but stops short of a general catalog of invariant types.
Examples
Uses cinema seat allocation, including the rule that one seat cannot belong to multiple tickets.
What it assumes
Assumes familiarity with domain objects and bounded contexts while introducing aggregates as consistency boundaries.
What you can do after
Apply it via aggregate design to keep related domain objects valid during a single transaction.
How it connects
Connects business invariants with domain models, aggregates, consistency boundaries, bounded contexts, and transactions.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Collaborative Software Design: How to facilitate domain modeling decisions. The section links point to the parts of the book it draws on.