Event-Sourcing
Event sourcing is a persistence pattern: rather than storing only an entity’s current state, you store the full, ordered sequence of state-changing events and derive current state by replaying them. The event log is an immutable audit trail and lets you rebuild or reinterpret state at any point in time.
In Spring DDD, an event-sourced aggregate persists its state as an append-only log of domain events. State is never overwritten — instead, the repository replays the full event history (or the history since the latest snapshot) to reconstruct the aggregate on every load.
The event-sourcing runtime is provided by spring-ddd-eventsourcing.
Add spring-ddd-starter-eventsourcing-jdbc to make it runnable, or use a full bundle
(spring-ddd-starter-jdbc or spring-ddd-starter-jpa) that already includes it.
In this section
-
Aggregates — annotation contract, base-class options, recording events,
@EventSourcingHandler, version & identity, deletion. -
Repositories — declaring and injecting a repository,
findById/save/existsById, bulk loading. -
Snapshots — snapshot thresholds, per-aggregate policy, enabling and disabling snapshots.
-
Per-aggregate event tables — routing an aggregate to its own table with
@EventTable, grouping, global position. -
Schema evolution — renaming and transforming events with upcasters.