Course contentsShow
← Cloud and Infrastructure
Lesson 573 of 2,98910. API Gateway and Event-Driven PatternsFree lesson

Event Sourcing Fundamentals

Storing state as a sequence of events rather than current values, enabling complete audit trails.

Event Sourcing Fundamentals

You'll learn: How storing every state change as an event creates a complete, append-only history of your system.

The Core Idea

Most applications store only the current state of data — like your bank account balance showing 1,000.∗∗EventSourcing∗∗takesadifferentapproach:insteadofstoringthecurrentvalue,youstore∗everyevent∗thatledtothatstate.Yourbalanceisn′tstoredas"1,000. **Event Sourcing** takes a different approach: instead of storing the current value, you store *every event* that led to that state. Your balance isn't stored as "1,000" — it's stored as a sequence: "Deposited 500,Withdrew500, Withdrew 200, Deposited $700."

Think of it like a bank statement versus a balance display. Traditional systems only show today's balance. Event Sourcing keeps the entire statement, letting you replay transactions to arrive at any point in time.

How It Works

In Event Sourcing, you:

  1. Capture every state change as an immutable event (e.g., OrderPlaced, PaymentProcessed, ItemShipped)
  2. Append events to an event store (a specialized database or log)
  3. Rebuild current state by replaying events from the beginning
  4. Never delete or modify past events — only add new ones

Why It Matters

Complete audit trail: Every change is preserved forever. Perfect for compliance, debugging, or understanding "how did we get here?"

Time travel: Replay events to see what your system looked like at any past moment.

Event-driven integration: Other systems can subscribe to your event stream and react to changes in real-time.

The Trade-Off

Event Sourcing adds complexity — you must design events carefully and manage potentially large event streams. It's not for every use case, but excels where history and auditability matter.

Key Takeaway: Event Sourcing stores state as a sequence of immutable events rather than current values, providing a complete, replayable history of all changes in your system.