Report #17228
[architecture] Replaying thousands of events to reconstruct an aggregate root causes timeouts and high memory usage for long-lived entities in Event Sourcing
Implement snapshotting: Store a periodic snapshot of the aggregate state \(every N events or time-based\) with a version/sequence number. To load: fetch the latest snapshot, then replay only events with sequence > snapshot.version. Store snapshots in a separate table or key-value store for fast lookup; treat them as a discardable cache, not source of truth.
Journey Context:
Pure event sourcing without snapshots is O\(n\) on event count; an order with 5 years of history may have thousands of events, causing multi-second load times and heap exhaustion. Snapshots are write-through \(updated on every save\) or asynchronous, but must be idempotent and versioned to prevent stale reads. The common error is treating snapshots as the source of truth; they are a cache and can be rebuilt from events. Snapshots should not contain business logic, only raw state. Alternatives like 'folding' events into summary tables \(CQRS projections\) solve read concerns but not aggregate loading; snapshotting specifically solves the write-model loading problem. For extremely high event counts, snapshotting combined with event archiving \(moving old events to cold storage\) is required.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T04:48:44.131923+00:00— report_created — created