Whether you’re new to Event Sourcing or have adopted the pattern before, we’re sure you’ve heard again and again about this particular benefit: the immutability of events.
It’s also likely that the context of this was around auditing. However, the true advantages of immutability extend far beyond this.
Let’s explore what we mean by immutability and why you should embrace it.
In Event Sourcing, immutability describes the practice and policy of not updating or changing events after they have been persisted in your database. Instead, whenever any property is altered, a new event is appended in the stream that holds the data.
This process is inherent to Event Sourcing as a concept; to make any change in an event sourced system, a domain-specific event is emitted in as much detail as needed, rather than mutating a row in a table.
Best practice is to use an event based state transition database like EventStoreDB, which natively stores these unchanged events as a log. In turn, you can take advantage of the benefits we’re about to go into.
Harnessing the power of immutable data
1. Keep the story behind your data
By keeping state change rather than overwriting data, you preserve business context. As such, you’ll gain insight into your system and can answer questions historically.
An example of this in practice is Wiser’s retail pricing intelligence platform. They used EventStoreDB hosted on Event Store Cloud to build an application that has transformed client data into actionable and competitive pricing intelligence.
For their platform to be successful, it was vital that clients could trust the data coming out of the system, which means that any pricing recommendation could be explained and recreated given the specific historical data used. Event Sourcing presented a logical solution to this and other requirements, such as the need for scalability.
The use of EventStoreDB has allowed the Wiser team to architect a solution spanning multiple data types - including purchase feeds, real time pricing information, sales history and customer data - as well as multiple online and offline data sources.
As a consequence, robust guidance on pricing optimization plus visibility of and accountability for any state changes is easily accessible where no data is lost. Being able to ask questions and get answers in this way immediately from historic data provides Wiser with an enormous competitive advantage.
2. Save time debugging
When something fails in production, would you rather have:
- Rows in relational tables showing your current state?
- A detailed, meaningful history of all state changes?
In the first scenario, previous data has been overwritten. You might know parts are wrong, but would lack the insight as to why. In some cases, you might not even know what’s wrong at all.
In contrast, with your event sourced system, debugging and support is manageable as you can see what, why and when changes were made to your data. Rather than focusing on finding the problem, you can instead work on fixing it.
3. Be confident when correcting errors
Complex systems naturally have upstream logic that can change downstream parts. When upstream components make mistakes, what happens when it cascades down to customers?
Fixing the source of problems and its local data is often the simple part; questions like “how should dependent components react to the correction” and “have any intermediate actions happened in the meantime” must also be answered. And the longer it takes to discover the problem, the harder it is to fix.
So how is correcting errors easier with an immutable event store?
Firstly, you can use a new event to correct the mistake and drive corrective workflows saving you time and effort. Secondly, it saves you the risk of transforming live data in a public environment; in a traditional database, the correcting act of changing data in a production environment gets lost and forgotten. Immutability forces the use of corrective events so you can capture the change, the reason and when the information was amended in the system of record itself.
4. An audit log to help you understand past decision making
In your immutable store, data cannot be altered. As such, Immutable events in the context of event sourcing means you’ll use the same data for auditing to make subsequent decisions, guaranteeing that auditing data is accurate. This is essential in some domains.
5. Enhance the user experience when errors occur
When your system experiences errors, it's important that communication with users remains open and fast.
With your immutable store, you can inform users of all changes made to their data since it has not been overwritten. They can even have visibility of their data if required. Additionally, you can communicate the system state more accurately by providing a clear record of everything that caused a change to your user’s data. This helps build trust with your users and wouldn’t be possible with a mutable store.
Beyond intentional data loss architecture
Gain a robust, reliable system and embrace immutability with operational database EventStoreDB. Download the open source version.