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. It pairs naturally with CQRS, since the same event log that rebuilds write-side state can also feed read-side projections, though the two patterns can be adopted independently. 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 11 focused tables and 121 indexed concepts, 95 flashcards. Below is a complete table-by-table outline of this topic, spanning foundational concepts through advanced details.
A jump-to index of every table row in this cheat sheet.
An interactive map of every table and concept in this topic.
Table 1: Core Concepts
Start here—these are the building blocks every event-sourced system is assembled from, and the rest of the cheat sheet assumes you know them. The mental model worth holding onto: commands ask for a change, aggregates decide whether it's allowed and emit events, those events get appended to a stream, and projections fold them back into shapes you can actually query.
| 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 • the rule of thumb: one aggregate, one stream, one transaction | ||
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 | ||
PlaceOrderCommand(customerId, items) | • Request to perform an action that triggers business logic • validated against current state • produces zero or more events if successful | ||
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 eventually consistent • optimized for read performance not writes | ||
if event_count > 1000: save_snapshot(state) | • Cached aggregate state at a point in time to avoid replaying thousands of events • optimization that doesn't affect correctness | ||
stream_id = f"Order-{order_id}"events = store.read(stream_id) | • Ordered sequence of events for one aggregate instance • maintains causality • each stream has a unique identifier tied to a business entity | ||
Orange sticky note: "OrderPlaced"-- notes placed left-to-right on a timeline | • Workshop technique for discovering a domain's events collaboratively with sticky notes • surfaces the event vocabulary and stream boundaries before any code is written | ||
INSERT INTO events (...values)-- No UPDATE or DELETE | • Storage model where new records are only added, never modified • events are immutable facts • ensures complete audit trail and temporal integrity | ||
state_at = replay_until(timestamp)balance = get_balance("2026-03-15") | • Ability to query system state at any point in history by replaying events up to that moment • enables regulatory compliance and forensic analysis |