Modeling Events
Learn how to design and model events that accurately represent your domain and business processes.
Event modeling is the practice of designing events that capture meaningful business occurrences in your domain. Well-modeled events serve as a clear communication tool between technical teams and domain experts, forming the foundation of your event-sourced system.
The goal is to create events that are expressive, complete, and aligned with how your business thinks about and describes state changes in the domain.
- OrderShipped - Specific action, past tense
- PaymentReceived - Clear business meaning
- CustomerRegistered - Domain language
- InventoryAdjusted - Intentional and precise
- OrderUpdate - Vague, present tense
- DataChanged - No business meaning
- RecordModified - Technical language
- Thing - Too generic, unclear intent
1. Use Past Tense
Events represent facts that have already occurred. Always use past tense to make this clear.
2. Use Domain Language
Event names should use the language of your business domain, not technical jargon.
3. Be Specific
Avoid generic names. Be specific about what happened.
4. Capture Intent
Event names should convey why something happened, not just what changed.
Deciding the right level of detail for events is crucial. Too coarse and you lose valuable information; too fine and you create complexity.
Fine-Grained Events
Multiple small events for each atomic change
- • Detailed audit trail
- • Maximum flexibility
- • Easy to build varied projections
- • More events to manage
- • Complex event sequences
- • Potential performance impact
Coarse-Grained Events
Fewer, more comprehensive events
- • Simpler event model
- • Fewer events to process
- • Easier to understand
- • Loss of granular detail
- • Less flexibility
- • May bundle unrelated changes
Finding the Right Balance
Choose granularity based on your business needs. Fine-grained for audit-critical domains (finance, healthcare), coarse-grained for simpler workflows. You can always split coarse events later, but combining fine-grained events retroactively is harder.
Events should contain all necessary information to understand what happened without requiring additional lookups.
Essential Event Properties
Example: Well-Structured Event
{
"eventId": "evt_1a2b3c4d",
"eventType": "OrderPlaced",
"eventVersion": "1.0",
"timestamp": "2024-11-12T15:30:00Z",
"aggregateId": "order_12345",
"aggregateType": "Order",
"data": {
"customerId": "cust_789",
"orderTotal": 159.99,
"currency": "USD",
"items": [
{
"productId": "prod_456",
"productName": "Blue Widget",
"quantity": 2,
"unitPrice": 49.99
},
{
"productId": "prod_789",
"productName": "Red Gadget",
"quantity": 1,
"unitPrice": 60.01
}
],
"shippingAddress": {
"street": "123 Main St",
"city": "Springfield",
"postalCode": "12345",
"country": "US"
}
},
"metadata": {
"userId": "user_321",
"correlationId": "corr_abc123",
"causationId": "cmd_def456"
}
}- •Events that are too generic: "StateChanged" or "DataUpdated" events provide no business value
- •Including behavior in events: Events should be pure data with no business logic
- •Incomplete event data: Requiring additional queries to understand the event defeats the purpose
- •Mutable references: Storing references to data that might change or be deleted
- •Technical language: Using database or implementation terms instead of domain language
- Events capture business facts in past tense using domain language
- Choose granularity based on your audit and flexibility requirements
- Include all necessary context to make events self-contained
- Event names should clearly communicate what happened and why
- Collaborate with domain experts to discover the right events