Why does replaying an aggregate's full event history on every command become a real problem, and how do snapshots fix it?
Every command against an aggregate requires reconstructing its current state, and without a snapshot, that means replaying every event the aggregate has ever applied, from the very first one, on every single load. For an aggregate with a handful of events, this is instant and unnoticeable; for a long-lived, heavily used aggregate — like a bank account with fifty thousand transaction events accumulated over years — replaying all of that history on every command becomes a real, measurable performance cost, since most of it hasn't changed in a long time. A snapshot fixes this by periodically saving a copy of the aggregate's state at a specific point in its history, so loading the aggregate becomes 'load the snapshot directly, then replay only the events that happened since' instead of replaying everything from the beginning. This turns loading cost from something that grows with an aggregate's entire lifetime event count into something that only grows with events since the most recent snapshot.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response