Skip to content

Constraints

Constraints are server-side rules enforced in the Chronicle kernel before events are committed. They protect invariants that must hold under concurrency — uniqueness being the canonical case. Two built-in forms cover the common cases; complex rules delegate to a file.

constraint <Name>
unique <property> on <EventType> ← unique property constraint
constraint <Name>
unique event <EventType> ← unique event type constraint
constraint <Name>
file <Path> ← custom C# implementation
FormMeaning
unique <property> on <EventType>No two event sources may commit the event type with the same value for the property.
unique event <EventType>The event type may occur at most once per event source.
file <Path>The rule is implemented in C# in the referenced file.
constraint UniqueInvoiceNumber
unique invoiceNumber on InvoiceRegistered
constraint OneRegistrationPerInvoice
unique event InvoiceRegistered
constraint InvoiceStatusTransition
file Constraints/InvoiceStatusTransitionConstraint.cs
  • Constraints belong in the StateChange slice whose events they guard.
  • Use a constraint — not command validation — for any rule that must hold under concurrent writers; validation happens before the append, constraints are enforced atomically at the event store.