Part 1: Event Sourcing Unveiled

Brett FleischerBrett Fleischer
6 min read

Background

The world runs on data. At some point, all of us have been exposed to both the storing and sharing of data in one form or another. This may be as simple as an Excel spreadsheet keeping track of monthly expenses or it could be as complex as a fully normalized relational database instance.

All software systems can have stateful and stateless information. Stateless information remains unaffected by the current data within the system. Event Sourcing primarily deals with stateful information, such as a loan amount, a user name, or the current date. That is what I will illustrate in this post.

Brief History of Event Sourcing

Early Financial Principles

The roots of Event Sourcing can be traced back to the world's first printed book-keeping dissertation by the father of accounting Luca Pacioli (Ovunda, 2015), seen in the center of the image below (de' Barbari, 1495–1500).

In his treatise, the Double-Entry Bookkeeping (DEB) method was introduced. The DEB method is a foundational accounting method where every financial transaction affects at least two accounts, which ensures that the accounting equation (Assets = Liabilities + Equity) remains balanced. This method has the following core principles:

  • Duality: Every transaction has two equal and opposite effects.

  • Balancing Accounts: The total debits must be equivalent to the total credits for every transaction.

  • Ledger System: Transactions are recorded in journals and then posted to ledgers, categorized into various accounts.

Modern Financial Principles

Modern financial practices rely heavily on first principles, such as the DEB method. Financial systems continue to use these methods for an audit trail of transactions, precise tracking of transactions, and accurate financial statements for reporting and regulatory compliance.

The Rise of Event Sourcing

In the 1990s and early 2000s, as software systems grew in complexity, the limitations of traditional CRUD operations became apparent. Systems needed better ways to manage state and ensure data consistency.

A software architectural pattern began to gain traction as developers sought methods to improve audibility, scalability, and reliability. One main driving force was Eric Evans’ book, Domain-Driven Design (2003), which emphasizes modelling complex business domains accurately with a detailed history of state changes. This played a crucial role in popularizing Event Sourcing.

What is Event Sourcing?

Event Sourcing is a software architectural pattern where changes within a system are stored as a series of events in an append-only manner.

Key Concepts and Terminology

Event: A single unit of data that indicates an action occurred directly, as a result of an external command, or internally from an automatically generated command.

Event Store: An optimized database management tool for storing events within a system.

Aggregate: A stateful domain model that can be altered by applying one or more events from the event store. The application of events for an aggregate represents the sum of incremental changes for a domain model, up to and including the final event applied.

Command: An intent to alter the state of the system. A successful command should result in appending one or more events to the event store.

The Benefits

  • Auditability: Each state change is recorded as an immutable event within an event store, providing an extensive audit trail.

  • Reproducibility: The aggregate state can be rebuilt by replaying events up to a point in time or an event version number.

  • Scalability: Event Sourcing can improve scalability by decoupling write and read operations.

  • Flexibility: The granularity of events stored allows for easy adaptation and extension as the system's requirements evolve.

Real-world Use Cases

Many industries have adopted Event Sourcing due to its benefits over traditional CRUD and Relational Database Management Systems (RDBMS). A few notable industries that use this pattern are:

Finance

a pile of gold and silver bitcoins

Strict regulations are placed on banks, trading firms, and insurance companies within the financial industry. To comply with these regulations, financial institutions require robust data storage solutions that offer immutable audit logs. This ensures compliance and fosters customer trust by maintaining transparency and auditability in their system processes. Notable companies within the finance industry that use this pattern are:

  • Revolut: uses an open-source event-native database (Alvargonzález, 2020)

  • ING: uses Apache Flink for event-driven architecture (Curry On!, 2018)

  • Wise: webhooks indicate the use of event-driven architecture (Wise, no date)

Healthcare

people in white shirt holding clear drinking glasses

Constant adaptation to changing regulations is required for healthcare providers such as health insurers, hospitals, and health solution providers. Healthcare systems often are migrated or in the process of migration from legacy to newer systems. These constant changes in the system favour a solution which is highly flexible and scalable. Notable companies within the healthcare industry that use this pattern are:

  • Cerbo (formerly known as MDHQ): webhooks indicate the use of event-driven architecture

  • Epic Systems: their large-scale ingest and representation of data through Cosmos DB indicates event-driven architecture

Transport

Big corporate shipment center with many cargo semi trucks unloading and uploading retail products for further retail shipment. Global market concept.

Accurate and real-time data monitoring of packages is crucial for transportation companies involved in shipping, freight, and logistics. Comprehensive data analysis is critical for transportation companies to calculate efficiencies and track compliance targets such as carbon emissions. These constraints on data reliability and availability are clear indications of a solution that must be fully scalable, reliable, and auditable. Notable companies within the transport industry that use this pattern are:

  • DB Systel: an in-house event management tool that indicates event-driven architecture (Successful deployment in DB vaccination centres, no date)

Conclusion

Event Sourcing is a powerful architectural pattern where state changes are recorded as a series of immutable events, offering benefits like auditability, reproducibility, scalability, and flexibility. By tracing its roots back to the foundational principles of Double-Entry Bookkeeping introduced by Luca Pacioli, we see how the need for accurate, auditable records has evolved over centuries. Just as the DEB method revolutionized financial accounting, Event Sourcing provides a superior solution for maintaining data integrity and consistency in modern software systems. This historical perspective underscores the enduring importance of meticulous record-keeping and state management, making Event Sourcing a natural progression in the quest for reliable and transparent data systems.

Join the Journey

In this series, I aim to take you through the journey of learning and implementing the Event Sourcing architectural pattern, sharing the insights and knowledge I’ve gained so far.

Each post will highlight key concepts, practical implementations, and real-world applications, providing a comprehensive understanding of Event Sourcing. As I continue to learn and explore this fascinating architectural pattern, I’ll document my discoveries and experiences, adding value by showing how to overcome challenges and apply best practices.

Whether you’re a beginner or looking to deepen your understanding, this series will guide you through the essentials and beyond, making the learning process engaging and informative.

References

de' Barbari, J. (1495–1500). Portrait of Luca Pacioli [Tempera on panel]. Capodimonte Museum, Naples. Available at: https://upload.wikimedia.org/wikipedia/commons/thumb/2/2a/Pacioli.jpg/480px-Pacioli.jpg (Accessed: 3 August 2024).

Ovunda, A.S. (2015) 'Luca Pacioli’s double-entry system of accounting: A critique.', CORE. Available at: https://core.ac.uk/reader/234631058 (Accessed: 27 July 2024).

Alvargonzález, C.L. (2020) 'Event Streaming: The Revolut way', Medium, 22 July. Available at: https://medium.com/revolut/event-streaming-the-revolut-way-9d928005ddf7 (Accessed: 28 July 2024).

Wise: online money transfers | international banking features (no date) Wise. Available at: https://docs.wise.com/api-docs/features/webhooks-notifications/event-handling (Accessed: 28 July 2024).

Curry On! (2018) 'Bas Geerdink - streaming analytics: how to get fast predictions from real-time data', YouTube. Available at: https://www.youtube.com/watch?v=A2nQzSfZ3fE (Accessed: 28 July 2024).

Successful deployment in DB vaccination centres (no date) DB Systel. Available at: https://www.dbsystel.de/dbsystel-en/about-us/Digital-Stories-en/Successful-deployment-in-DB-vaccination-centres--6588704 (Accessed: 28 July 2024).

0
Subscribe to my newsletter

Read articles from Brett Fleischer directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Brett Fleischer
Brett Fleischer