Web apps & software

What is event sourcing?

Event sourcing is a way of storing data in which you keep the full sequence of changes (events) rather than only the latest values. The current state of an account, order or booking is calculated by replaying its events in order.

Example

A traditional bank-balance table holds one number. An event-sourced account instead stores "opened", "deposited 200", "withdrew 50", "fee charged 2". The balance is the sum. Nothing is overwritten or deleted; a mistake is corrected by adding a new compensating event, much as an accountant posts a reversing entry instead of erasing a ledger line.

What you gain

  • A complete, trustworthy history: who changed what, and when, for every record.
  • The ability to answer new questions about the past, because the raw events are still there.
  • Easy creation of new read views by replaying history into a fresh projection.

What it costs

Event schemas must be versioned forever, since old events never go away. Replaying long histories gets slow, so systems store periodic snapshots. Deleting personal data for privacy requests needs a plan, such as encrypting each person's events with a key you can destroy. Developers new to the pattern need time to adjust. It suits finance, logistics and compliance-heavy domains; for a brochure site or simple CRM it is overkill, and a normal audit log gives most of the benefit.

Questions, answered

No. An audit log records changes beside the real data; in event sourcing the events are the real data.

Dedicated stores such as EventStoreDB exist, but PostgreSQL tables with an append-only design are common too.

By the Stegnor team · Updated