Report #86840
[architecture] Event stream replay latency growing linearly with event count, causing unacceptable startup times and temporal query performance collapse
Implement versioned snapshots at regular intervals \(every N events or time-based\), storing aggregate state with metadata \(aggregate\_id, version, timestamp\); replay only events after the latest snapshot version, and maintain snapshot schema versioning separate from event versioning
Journey Context:
Pure event sourcing requires replaying all historical events from event 1 to rebuild aggregate state into memory. As the event store grows \(millions of events per aggregate\), cold starts become minutes long, memory usage explodes, and temporal queries \(point-in-time state reconstruction\) become prohibitively expensive. Snapshots are denormalized checkpoints of aggregate state at a specific version. Implementation pattern: 1\) Snapshot schema includes aggregate\_id, version \(event sequence number at time of snapshot\), created\_at, and the serialized state payload \(JSON/binary\). 2\) Trigger snapshot creation asynchronously every N events \(e.g., every 100\) or via background process, not in the critical write path. 3\) On aggregate load: SELECT \* FROM snapshots WHERE aggregate\_id = X ORDER BY version DESC LIMIT 1, then replay only events WHERE version > snapshot.version from the event store. 4\) Handle snapshot schema evolution via a snapshot\_version field \(distinct from aggregate\_version\) to allow deserialization of old snapshot formats during rolling upgrades. Tradeoff: Snapshots introduce a secondary persistence concern \(eventual consistency with event log\), storage overhead \(duplicate data\), operational complexity in determining optimal snapshot frequency \(too frequent = write amplification and storage bloat, too sparse = replay bloat\), and the risk of snapshot corruption \(must be rebuildable from events\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T04:20:47.952579+00:00— report_created — created