Events
Events represent the sequence of state-changing events allowing for a comprehensive history of state transformations, easy debugging, and complex business logic support.
- Auditability: Records every change, ensuring full traceability.
- Replayability: Enables state reconstruction, aiding in debugging and analysis.
- Scalability: Efficiently manages high loads through decoupling.
- Resilience: Recovers state post-failure from the event log.
- Insightful Data: Offers deep insights through historical analysis.
- Real-World Alignment: Domain events mirror real-life business processes.
Creating Events
Events should be the representation of real domain events. You should define them by talking to a domain expert or using techniques like event storming. In our banking example, an event could be a deposit or a withdrawal.
Because events will be stored in a database, they should be serializable. In Rust, you can use the serde
crate to derive the Serialize
and Deserialize
traits.
domain/src/todolist_event.rs
use serde::{Deserialize, Serialize};
use crate::todolist_scalar::{TaskIndex, TaskName};
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum TodoListEvent {
TaskAdded(TaskIndex, TaskName),
TaskRemoved(TaskIndex),
TaskCompleted(TaskIndex),
}