Event Sourcing Explained

Store every change as an immutable event — enabling perfect audit trails, temporal queries, and the ability to reconstruct any past state.

Event Sourcing

Event sourcing is an architectural pattern where the state of an application is determined by a sequence of immutable events rather than by storing the current state directly, providing a complete audit trail and the ability to reconstruct any past state.

Explanation

Traditional applications store only the current state: a bank account has a balance of $500. Event sourcing stores every event that led to that state: deposited $1000, withdrew $200, transferred $300. The current balance is derived by replaying all events. This seems redundant but unlocks powerful capabilities. The event log is an immutable, append-only record of everything that happened. You can reconstruct the state at any point in time (what was the balance on March 15?), build new views of the data retroactively (add a new report that analyzes historical events), and maintain a perfect audit trail (who did what, when). Events are facts — they cannot be changed or deleted. Event sourcing pairs naturally with CQRS (Command Query Responsibility Segregation): commands append events to the event store, and read models are built by projecting events into optimized query views. The challenge is complexity: event schemas evolve over time (schema versioning), replaying millions of events can be slow (snapshots help), and eventual consistency between the event store and read models requires careful handling.

Bookuvai Implementation

Bookuvai implements event sourcing for domains where auditability and temporal queries are critical — financial systems, compliance platforms, and collaborative applications. Our event store uses append-only tables with JSON event payloads, schema versioning for event evolution, and periodic snapshots for performance. Projections build read-optimized views asynchronously.

Key Facts

  • Events are immutable facts — append-only, never updated or deleted
  • Any past state can be reconstructed by replaying events up to that point
  • Pairs naturally with CQRS for optimized read and write models
  • Snapshots prevent slow replay when the event log grows large
  • Schema versioning handles event format evolution over time

Related Terms

Frequently Asked Questions

When should I use event sourcing?
Use event sourcing when you need a complete audit trail, temporal queries ("what was the state on date X?"), or the ability to derive new views from historical data. Avoid it for simple CRUD applications where the added complexity is not justified.
How do I handle event schema changes?
Use event versioning: each event type has a version number, and upcasters transform old event formats to the current format during replay. Never modify existing events — add new event types instead.
Is event sourcing the same as an event log?
An event log records events for monitoring or debugging. Event sourcing uses events as the authoritative source of truth — application state is derived entirely from events, not stored independently.