← All patterns
Data consistency · Architecture pattern

Event Sourcing

Keep domain events as the authoritative history and derive current state by replay.

The problem

Overwriting current balance loses the sequence of business facts needed to explain or reconstruct it.

When it fits

History and reconstruction are important enough to justify event contracts, stream concurrency and long-term replay maintenance.

The whole architecture

Architecture diagram

The event stream is authoritative; read projections and optional snapshots are derived from a known stream position.

Blue arrows are commands or queries; purple arrows carry persisted events; gray arrows show rebuild control.

100%

Scroll to pan. Select a component for its role.

event sourcing architectureThe event stream is authoritative; read projections and optional snapshots are derived from a known stream position. Blue arrows are commands or queries; purple arrows carry persisted events; gray arrows show rebuild control.Command processingRead projectionclient → command: commandclient → query: querycommand → events: append with versionevents → projector: persisted eventsprojector → read: projectquery → read: read projectioncommand → snapshot: read snapshotrebuild → projector: replay controlcommandqueryappend with versionpersisted eventsprojectread projectionread snapshotreplay controlA query can lag after an event append unless the contract coordinates read-your-write behavior.ClientsCommands / queriesEvaluate the command against aggregate state and protect concurrent appends.Command handlerExpected stream versionPersist domain facts as the source of truth in this architecture.Event storeAuthoritative historyApply events with defined stream ordering and version semantics.ProjectorDeterministic reducerThe projection can be rebuilt from a valid event boundary.Read modelDerived query stateThe query interface can expose progress or a pending state.Query APIRead-oriented contractA snapshot accelerates reconstruction without replacing authoritative event history.Optional snapshotState + event positionSeparate replay of derived state from live notifications or payments.Projection rebuildReplay without repeating external effects

Select a component, or focus it and press Enter, to read its role.

Walk through the design

Follow one operation

Select a step to highlight its participants. This conceptual walkthrough is separate from challenge scoring.

The event store is authoritative in this lesson. This differs from the SQL-authoritative CDC recovery practice.

Command handlerActive in this stepEvent storeActive in this stepProjectorWaitingRead modelWaiting
Step 1 of 3

Check the stream version

The command handler evaluates the operation against the current aggregate state and expected stream revision.

Trade-offs to make explicit

  • Events become the system of record; a projection or snapshot can accelerate reads but must remain tied to a valid event position.
  • Schema evolution, retention, privacy and deterministic replay add cost. Ordinary CRUD plus CDC does not by itself turn domain events into authoritative state.

Failure modes to plan for

  • Concurrent commands can append incompatible decisions unless stream versions or another concurrency control protect the invariant.
  • Replaying historical events can repeat external effects unless rebuilding projections is separated from live effect delivery.
Before you build

Explain your decision

Which records are authoritative, and how would you rebuild a projection without re-sending old notifications?

Use Plan & estimate inside practice to record your assumptions and trade-offs.

Connect concept to practice

Related challenges

Browse challenges →

These links open the original challenges. Existing round unlocks, completions and points apply.

Rebuild search while writes continue

Related prerequisite in replaying derived state. Its SQL records are authoritative and its CDC fixture is not a scored event-sourced domain.

Open challenge →

One transfer, two attempts

Related prerequisite in stable operation identities and local atomic effects.

Open challenge →

Further reading

Microsoft · Event sourcing ↗

Original PractiseGrid explanations and conceptual diagrams, with primary references for further study. Dedicated scored exercises can be added as coverage grows.