Skip to content
IT glossary
ArchitectureUpdated December 3, 2026

Event Sourcing

With Event Sourcing, a system saves what happened rather than just the latest values. It can reconstruct the current state by applying those recorded events in order.

The history is the record

A typical inventory app updates a row to say there are nine units in stock. An event-sourced app records facts such as “12 units received” and “3 units reserved.” The ordered event stream is the source of truth. A table showing current availability can still exist, but it is derived from the events and can be rebuilt from them. That is the key difference from keeping an audit log next to an authoritative table.

What happens on a write?

A command, such as ReserveStock, is a request that may be rejected. The handler loads the item's stream, applies the events in order to reconstruct its state, and checks whether enough units are available. If the check passes, it appends StockReserved. To prevent two requests from reserving the same stock, the append can require the stream to still be at the version the handler read. If another write has moved it forward, the handler reloads the stream and checks the request against the new state.

Example: two reservations

Stream: item-123
1. StockReceived(quantity=12)
2. StockReserved(quantity=3)
3. StockReserved(quantity=4)

There are nine units available at version 2 and five at version 3. If the second reservation is cancelled, the app can append ReservationReleased(quantity=4) instead of removing event 3. Replaying the stream means recalculating state, not repeating external actions such as sending a shipping request.

Reading efficiently

To display available stock across a warehouse, the app can maintain a projection: a read model shaped for that query. If a background worker updates it, the projection may briefly show an older count, so it should not be used to decide whether a new reservation can succeed. If the worker can receive an event twice, it must avoid applying the same change twice. A snapshot serves a different purpose: it saves an item's state at a known version so the write handler only needs to replay subsequent events.

When it's worth it

Inventory and ledger systems can benefit when operators need to explain how a balance was reached or rebuild a report from historical facts. For a simple settings screen, storing the latest values is usually enough. Event Sourcing adds storage and operational work, and new code must still be able to read older event formats. An append-only history also makes it important to plan what personal data should be kept out of the stream.

In interviews

Be ready to separate persistence from messaging. Putting events on a broker does not make a system event-sourced if its database rows are still authoritative. Likewise, CQRS separates the write and read models; it often pairs well with Event Sourcing, but either pattern can be used without the other.