AccountOpened, MoneyDeposited).
Defining Domain Events
In our framework, domain events are represented as a simple Rust enum, and we implement theDomainEvent trait to supply metadata about the event schema.
Event Design Guidelines
When designing events for your business domain, adhere to these guidelines:- Past Tense: Events represent facts that are set in stone. Always name them in the past tense (
AccountOpened,MoneyDeposited). - Immutable: Events represent history and should never be modified once committed. In Rust, derive
Clone,Debug, andPartialEqon your events, and keep them free of pointers, mutable references, or stateful handles. - Self-Contained: Events must carry all the parameters that represent the delta of the change. A
MoneyDepositedevent must carry theamountthat was deposited so that replays and read model projections can calculate the resulting balance.