Report #70646
[architecture] How to prevent slow aggregate rebuild when replaying thousands of events in event sourcing
Implement snapshotting by periodically persisting the aggregate state to a separate snapshots table \(aggregate\_id, version, state\_payload, created\_at\). When loading an aggregate, fetch the latest snapshot \(version N\) and replay only events after N. Store snapshots every N events \(e.g., every 100 events\) or on specific milestones. Version the snapshot schema to handle serialization evolution \(upcasting\).
Journey Context:
Teams adopting event sourcing often hit a performance wall when aggregates accumulate thousands of events, causing O\(n\) rebuild times and timeouts. Some try to optimize the event store queries with better indexing, but this is asymptotically futile. Others try to keep aggregates in memory \(caching\), which fails on node restarts. Snapshotting introduces a space-time tradeoff \(disk for speed\) but adds complexity: you must handle 'snapshot staleness' \(events between snapshot and now\) and schema migration of snapshot blobs. The anti-pattern is serializing the aggregate as JSON without versioning, making it impossible to refactor the domain model later.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T01:09:19.650626+00:00— report_created — created