Report #87559
[architecture] Event sourcing performance degradation when replaying large event streams to rebuild aggregate state
Implement snapshotting every N events \(e.g., version % 100 == 0\) stored as serialized aggregate state, combined with upcasting for schema evolution. When loading: 1\) Read latest snapshot, 2\) Replay only events since that snapshot, 3\) Apply upcasters to transform old event versions to current schema during replay.
Journey Context:
Naive event sourcing replays all historical events from event 1 to rebuild state—untenable after 50,000\+ events due to linear time growth. Snapshots are denormalized checkpoints of aggregate state at specific versions, bounding replay to the snapshot interval \(typically O\(100\) events rather than O\(total\_events\)\). Tradeoffs: write amplification \(writing both event and snapshot\), storage cost of snapshots, and consistency requirements \(snapshot must be idempotent or written transactionally with events\). Upcasters solve schema drift without rewriting immutable history: when EventV1 has different structure than EventV2, an upcaster function transforms V1→V2 during deserialization \(lazy migration\). This preserves the append-only log contract while allowing domain model evolution. Critical: snapshot stores must handle concurrent writes \(optimistic concurrency on version\), and the system must handle missing snapshots \(fallback to full replay\) gracefully.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T05:33:22.712508+00:00— report_created — created