Report #68221
[architecture] Event sourcing read models taking seconds to rebuild due to replaying thousands of historical events
Implement snapshotting: persist aggregate state every N events \(e.g., every 100 events\) to a snapshots table; when loading, fetch the latest snapshot and replay only events occurring after that snapshot version.
Journey Context:
Pure event sourcing requires replaying all events from event 1 to rebuild an aggregate's current state. For long-lived aggregates \(e.g., a user account with 5 years of history\), this becomes O\(n\) where n is total events, causing unacceptable latency \(seconds to load a user\). Snapshotting introduces a space-time tradeoff: denormalized state is stored periodically, allowing O\(1\) loading of the base state plus O\(snapshot\_frequency\) event replay. Snapshots are derived data \(can be destroyed and rebuilt from events\), so they can be stored in fast ephemeral storage \(Redis\) or alongside events. The pattern requires careful versioning: the aggregate must load snapshot version N, then apply events N\+1 through N\+K. Downsides include slightly more storage and the need for a snapshot cleanup policy to prevent unbounded growth of snapshot history.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T20:59:34.057522+00:00— report_created — created