Event Sourcing is an architectural pattern where state changes are stored as a sequence of immutable events rather than overwriting current state in a database. Born from Domain-Driven Design and financial ledger systems, this pattern treats events as the single source of truth, allowing complete audit trails and the ability to reconstruct any past state by replaying the event log. Unlike traditional CRUD systems that lose historical context with each update, Event Sourcing preserves every state transition as an append-only log—enabling powerful capabilities like time-travel queries, retroactive corrections, and temporal analysis that are difficult or impossible with conventional persistence. The key mental model is simple: instead of storing where you are, store how you got there—every event is a fact that cannot be changed, only compensated for or refined with new events.
What This Cheat Sheet Covers
This topic spans 12 focused tables and 120 indexed concepts. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
Table 1: Core Concepts
| Concept | Example | Description |
|---|---|---|
events.append(OrderPlaced)events.append(OrderShipped) | • Append-only database that stores every state change as an immutable event • serves as the single source of truth for the system | |
class Order: def place(self): return OrderPlaced(...) | • Domain entity that enforces business rules and produces events • reconstructed by replaying its event stream • defines the consistency boundary | |
OrderPlaced(orderId, customerId, items, timestamp) | • Immutable record of a past action written in past tense • contains all data needed to describe what happened • the atomic unit of state change | |
state = reduce(events, apply, initial) | • Process of rebuilding aggregate state from scratch by sequentially applying all historical events • enables time-travel and state reconstruction | |
def on_OrderPlaced(event): db.orders.insert(...) | • Read model built by processing events to answer specific queries • typically eventual consistent • optimized for read performance not writes |