Open the editor

Event sourcing

Store every change as an event; current state is whatever the events add up to.

Event sourcing diagram: Commands and aggregates, Event store, Snapshots, Projections, Subscribers

With event sourcing, the system stores every change to its data as an event in an append-only log (OrderPlaced, ItemAdded, OrderShipped) instead of overwriting the current state. To get an order's current state, the code replays its events. The event log is the source of truth; every other view of the data is derived from it.

You get a complete audit trail, the ability to answer "what did this look like last Tuesday", and the freedom to build new read models from history at any time. In return, the events become a permanent contract, and changing their schema takes care.

The parts of the pattern

Commands and aggregates
A handler loads an aggregate by replaying its events, checks the command against the rules and emits new events.
Event store
An append-only log of events per aggregate, with optimistic concurrency on each stream.
Snapshots
Saved states every N events, so long streams do not need a full replay.
Projections
Read models built by processing events, such as an order list or a revenue report.
Subscribers
Other services that react to the events, such as email or search indexing.

How it works

  1. A user adds an item to an order.
  2. The handler loads the latest snapshot and the events after it to rebuild the order.
  3. It checks the rule (the order is not shipped yet) and appends ItemAdded to the store.
  4. Projections and subscribers receive the new event and update their views.
  5. A new report can be built later by replaying all events from the start.

When to use it, and when not to

Good fit

  • Auditing and traceability are requirements: finance, healthcare, logistics.
  • The history itself has business value, or you expect to need new views of it.
  • Collaborative or long-running workflows where how you got here matters.

Think twice

  • Simple CRUD where only the current state matters.
  • The team is new to it and the deadline is tight: versioning events and rebuilding projections need experience.
  • You need to delete personal data easily: plan for crypto-shredding or separate stores first.

Edit this diagram

Click Open the diagram in the editor to get your own copy, saved in your browser. Rename the boxes to match your system, swap the generic boxes for technology icons from the palette, then export a PNG, SVG or PDF, or share a link. No sign-up.