Event Sourcing Fundamentals
What you'll learn: How to store your application's state as an immutable sequence of events instead of overwriting current values.
The Core Idea
Traditional systems store the current state of entities—like "User balance: 50," "AccountDebited 70." The current state is derived by replaying all events from the beginning.
Think of it like a bank statement versus your account balance. The statement lists every transaction (events), while your balance is just the sum. Event Sourcing keeps the full statement and calculates the balance when needed.
Why This Matters in Event-Driven Architecture
Event Sourcing naturally extends event-driven architecture. Instead of just publishing events to notify other systems, you also persist them as your source of truth. This gives you:
Complete audit trail: Every state change is recorded with context—who did what, when, and why.
Time travel: Replay events to see what your system looked like at any point in the past.
Debugging superpowers: Reproduce bugs by replaying the exact sequence of events that caused them.
Flexibility: Project events into different read models optimized for various queries.
Trade-offs to Consider
Event Sourcing isn't free. You must handle event schema evolution carefully, as old events never disappear. Performance requires careful design—replaying thousands of events for every read is expensive (solved with snapshots and CQRS patterns you'll learn later). The mental shift from CRUD to event-thinking can be challenging for teams.
Key Takeaway: Event Sourcing stores state as an append-only log of immutable events rather than mutable current values, enabling complete history tracking and temporal queries at the cost of increased complexity.