Skip to main content

What does "event sourcing" mean?

Event Sourcing is an architectural approach in which the system does not store an object's current state directly, but stores all the events that led to it.

The essence

Every data change is recorded as an event:

"Order created", "Item added", "Payment received".

To get the current state, the system simply replays all the events in order. This way, the database becomes a history log rather than a snapshot of the current state.

Example

The usual approach stores:

javascript
Order: {id: 1, status: "paid"}

Event Sourcing stores:

javascript
1. OrderCreated 2. ItemAdded 3. PaymentReceived

From these events, the order's current state can be recomputed at any moment.

Why this is needed

  • Full history of changes: convenient for auditing and analytics.
  • Easy rollback and state replay.
  • Natural integration with event-driven architecture (EDA).
  • Flexibility: data can be recomputed if the business rules change.

Drawbacks

  • Makes storing and reading data harder (you need "projections" for fast queries).
  • Harder to implement transactional integrity.

Summary:

Event Sourcing is a way of storing not the result but the history of events, letting you precisely restore the past and flexibly manage the system's state.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.