advanced
Event sourcing
Store state changes as an append-only event log when audit, replay, temporal queries, and explicit evolution justify the modeling cost.
Event sourcing persists state as an append-only sequence of domain events. Current state is derived by replaying or snapshotting. Benefits: audit trail, temporal queries, and natural integration via the same events. Costs: schema evolution, storage, and mental model complexity.
Trade-off: perfect history and replay versus operational burden and learning curve.
On interviews: contrast event sourcing with CRUD plus outbox; explain snapshots and upcasting old events.
Common pitfalls: events as integration DTOs without domain meaning; unbounded event store without compaction policy; replay without versioning strategy.
Checklist:
- Model events as domain facts, versioned.
- Use snapshots for long aggregates.
- Plan upcasters for schema changes.
- Separate internal events from public integration events.