Store every change as an event, and rebuild the current state by replaying them.
Event Sourcing stores every change as an event in an append-only log, instead of storing only the latest state. The current state is found by replaying the events.
Most systems store the current state. When something changes, the old value is overwritten. The row says the balance is 120, but not how it got there.
With Event Sourcing the events are the source of truth. Each event is a small fact named in the past tense: OrderPlaced, ItemAdded, PaymentReceived. The state is just a fold (a running total) over those events.
To change something, you send a command ("Withdraw 30"). The code loads the past events, rebuilds the current state, checks the rules, and, if all is fine, appends a new event. A command can be rejected, but an event, once stored, always happened.
| Piece | What it does | Example |
|---|---|---|
| Event | An immutable fact in the past tense, with data and a timestamp | MoneyWithdrawn { account: 7, amount: 30 } |
| Event store | An append-only database of events, grouped per stream | EventStoreDB, Kafka (with care), a SQL table |
| Aggregate / stream | One thing whose events are kept together in order | Account 7, Order 1042 |
| Command | A request to do something. It may be rejected | WithdrawMoney |
| Projection | Builds a read view by consuming events | Account summary table, search index |
| Snapshot | A saved copy of state at some event number | Balance 1,250 after event 5,000 |
| Command | Event | |
|---|---|---|
| Tense | Imperative: WithdrawMoney | Past: MoneyWithdrawn |
| Meaning | A wish. Could be refused | A fact. Already happened |
| Stored? | Usually not | Yes, forever |
| Count | One target | Zero or more listeners |
Tip: keep adding deposits. Without snapshots the replay count grows with every event. With snapshots it never passes the snapshot interval.
| Term | Meaning in easy words |
|---|---|
| Event | An immutable record of something that happened, named in the past tense |
| Event store | An append-only database that keeps events in order |
| Stream | The ordered events of one entity, such as one account |
| Aggregate | A group of objects treated as one unit that decides if a command is allowed |
| Replay / rehydrate | Apply the events in order to rebuild the state |
| Fold | Combine a list of events into one state value |
| Snapshot | A saved state at an event number, to skip old events |
| Projection | A read view built from events |
| Optimistic concurrency | Reject a write if the stream changed since you read it |
| Upcasting | Converting an old event shape to the new one when reading |
| Compensating event | A new event that fixes an earlier mistake |
| Choice | We gain | We lose |
|---|---|---|
| Events as truth | History, audit, replay | No simple SELECT of current state |
| Snapshots | Fast loading of long streams | Extra storage and code, snapshots must be kept in sync with event shapes |
| Small, focused events | Clear meaning and simple projections | More event types to manage |
| Large 'state changed' events | Few types | Meaning is lost, consumers are tightly coupled |
| Sync projections | Read your own writes | Slower writes and more coupling |
| Async projections | Fast writes, scalable reads | Lag and duplicate handling |