Event Sourcing

Don't just store the current state. Store the story of how you got there.

The Source of Truth

In a traditional CRUD database, when you update a user's address, the old address is lost forever. You only know the now.

With Event Sourcing, we persist every state change as an immutable event (e.g., `UserMovedAddress`, `OrderPlaced`, `ItemRemovedFromCart`). The current state is simply a derived view of all past events.

Why It Matters

  • Auditability: Perfect for finance and long term records. You can prove exactly who did what and when.
  • Time Based: "What did the cart look like last Tuesday at 2 PM?" Just replay events up to that timestamp.
  • Debugging: Copy the production event stream to a local environment and replay it step-by-step to reproduce a bug.

CQRS & Event Sourcing

The Write Side

Optimized for high-throughput writes. Validates commands and appends them to the Event Store.

The Projector

An async worker that listens to new events and updates specialized Read Models (SQL table, Redis cache).

The Read Side

Optimized for query speed. Can be denormalized and tailored to specific views.

Related Projects