In conventional software development, applications typically store their state in a database. To retrieve specific data, an application queries the database, and the results are used presented to the user.
However, Event Sourcing introduces a different approach. Instead of storing the final state of an object in the database, event-sourcing preserves the sequence of events that led to the current state of the object. By reapplying these events in sequence, the object’s previous state is reconstructed.
Event-Sourcing offers several significant benefits, with two standing out in particular:
- Built-in Audit-Trail: One of the primary advantages of Event-Sourcing is that it inherently provides an Audit-Trail. This means that you can always trace back the events that led to the current state of an object.
- Scalability: When implemented correctly, Event-Sourced systems can scale almost endlessly.
The concept of Event Sourcing has been around for years. Articles on the internet date back to 2005 (and maybe even further). However, after public cloud gained popularity, that’s when Event Sourcing started to become more popular.
Organisations that adopted Cloud-Native approaches redesigned their applications by breaking them down into smaller chunks. This enabled easier scalability, leading to reduced hosting costs.
Cloud-Native applications ensure high availability by avoiding direct communication with one another. Instead, they opt for asynchronous communication through queues. This approach aligns well with event sourcing principles.
Initially, in the industry, different projects developed their own event-sourcing frameworks. However, after some time, various Event-Stores and Event Sourcing frameworks emerged, making it much easier to implement Event Sourcing.
How to implement Event Sourcing
To make the subject tangible, consider the following situation. You are running a webshop. Customers can select products, proceed to checkout, make payments, and finally, their orders will be processed and eventually shipped to their address: