What is Event Sourcing? By David Boyne

What is Event Sourcing? By David Boyne

What is Event Sourcing?

Event Sourcing is a pattern the stores events in order, in a append-only log.

This can enable various use cases like keeping audits of changes, compliance requirements, deriving state from events, replaying and debugging.

Many applications query for the current state and we mutate that state but sometimes we need to know the story/history of how the current state got there. Storing events using Event Sourcing provides a pattern to help us understand how the current state of the application got to where it is.

As events occur within the system, they are captured and stored. Application state can be calculated using these events, even if you have a clean starting point, you can see previous events, and calculate the current state.

Store events in append-only log

  • At the heart of event sourcing, you store your events in an append-only log.

  • You read/write from this log and it is discouraged to delete/update any past events.

  • Any changes to events, are just new events onto the log, that way all mutations are captured in the log.

  • Great example of this is accounting ledger. Accountants want to track transactions made and these are recorded.

Derive state from events

  • As the data is captured as events within a log, this log can be viewed/processed to calculate state.

  • The target state may depend on the application querying the data, so often materialized views are created for applications.

  • Applications query the views to get the information they need. This can be cached or snapshots may be used in event stores to help with performance at larger scales.

  • As you see in the visual, the analytics platform and web application both have different requirements and state to display. They talk to different views to get this information, all derived from the event log.

  • Common pattern for this is CQRS (Command and Query Responsibility Segregation)

Audit and trace

  • As events are stored, it opens up possibilities for auditing and traceability.

  • Depending on your use case event sourcing can be a great pattern to help if you need to get an audit log of certain events within your architecture.

  • As the events are stored and materialized views can be used to query the events, various teams can read the data.

  • An example could be developer teams may want to replay events helping debug systems, compliance teams may use events for reports or product owners may want a new feature that allows users to see historic transactions within their banking account.

Extra Resources

Want to work together?

If you're interested in collaborating, I offer consulting, training, and workshops. I can support you throughout your event-driven architecture journey, from design to implementation. Feel free to reach out to discuss how we can work together, or explore my services on EventCatalog.

Download EDA Visuals

Join over 13,000 others learning EDA and download all the EDA visuals directly to your computer. This document updates everytime a new visual is added so make sure you come back to get the latest.

Download now →
Diagrams and thoughts by @boyney123 to help you learn.