Event Sourcing Fundamentals
You'll learn how event sourcing captures every state change as an immutable event, creating a complete audit trail of your system's history.
What Is Event Sourcing?
Instead of storing just the current state of your data (like a traditional database row), event sourcing stores every change as a separate event. Each event is immutable—once written, it never changes. The current state is derived by replaying all events from the beginning.
Think of it like a bank ledger: instead of just showing your current balance (0, deposited 50, deposited 500 current balance.
How It Works in Microservices
When something happens in your system—a user places an order, updates their profile, or cancels a subscription—you append an event to an event store:
OrderPlacedat timestamp XPaymentProcessedat timestamp YOrderShippedat timestamp Z
These events become the source of truth. You can rebuild any entity's state by replaying its events. You can also time-travel to see what the state was at any historical moment.
Key Benefits
Complete audit trail: Every change is preserved with full context
Time travel: Reconstruct past states for debugging or analysis
Event replay: Rebuild state if your database corrupts
Multiple views: Create different read models from the same events (pairs well with CQRS)
Considerations
Event sourcing adds complexity—you need to design events carefully and handle schema evolution. It's powerful for domains requiring auditability and historical analysis.
Key Takeaway: Event sourcing stores state changes as immutable events rather than overwriting current state, enabling complete history tracking and state reconstruction through event replay.