Event sourcing is a persistence pattern in which durable events describing accepted changes are the authoritative record for part of an application. Current-state objects and query views are derived from that history. Unlike primarily storing and updating the latest state, the pattern preserves the changes needed to reconstruct it. Conventional databases can also retain history without adopting this pattern.
How It Works
Application logic first evaluates a requested action against current state and business rules. If accepted, it records the resulting events durably and applies them to derive updated state. An event records something that happened, not an instruction that might still be rejected.
An event store keeps this durable, append-only history. Related events are commonly grouped into an ordered stream for an entity or aggregate—a group of related objects treated as one consistency boundary. Event sourcing requires meaningful ordering within relevant streams, not a separate system-wide log or one global order. The store can use a general-purpose database or a purpose-built implementation; persisting events and delivering messages to other services are separate responsibilities.
Replay and Query Views
Replay applies recorded events to a known starting state to reconstruct current state, or stops at a chosen point to reconstruct an earlier state. Correct reconstruction requires sufficient retained events, meaningful ordering and compatible replay logic. Ordinary business corrections usually add compensating events instead of editing historical facts. In a hypothetical reservation system, a cancellation event reverses the effect of a booking while leaving both events in the history.
Queries need not replay the full history on every read. Projections, including materialized views, organize event-derived data for convenient querying but are not authoritative. Optional snapshots capture state at a stream position so reconstruction can resume there and apply only later events. They shorten replay without replacing the authoritative event history. Event sourcing can support alternative views built from retained events, but those views cannot recover details never recorded. Historical queries and new views still require suitable processing logic.
Advertisement — FinchTrade.
FinchTrade services
Get startedHistorical Uses and Integration
The retained history can support auditing, debugging, recovery of derived state and historical analysis. Events that capture business context may explain changes more clearly than successive snapshots, but intent is visible only if recorded. An append-only record is not automatically a complete audit of every system action or proof of compliance.
Command Query Responsibility Segregation (CQRS) separates read and write models and is often paired with event sourcing, although neither pattern requires the other. Events may also be distributed to other services to trigger reactions. Such event-driven communication does not require events to be the authoritative storage, and event sourcing itself does not require microservices or message queues. Asynchronously updated projections can lag behind committed events even when authoritative writes provide strong consistency.
Costs and Suitability
Concurrent writers need conflict detection and handling so events are not accepted against stale state. For example, a stream-version check can reject an append if another writer has changed the stream; the application then reloads state and reevaluates the request. Evolving models and event formats require replay logic that remains compatible with older records.
Growing histories increase storage, replay and query costs. Developers must learn different approaches to modeling, testing and debugging, while operators must maintain projections and recovery processes. Integration handlers must tolerate duplicate deliveries, and replay must avoid repeating external effects such as payments or notifications. The pattern does not automatically improve performance or scalability. Choose event sourcing when historical reconstruction or auditability justifies these costs; otherwise, simpler current-state persistence may suffice.