In the previous module, you learned how event sourcing differs from traditional forms of data management since the source of truth is an immutable event log rather than a mutable table. But why would you consider implementing event sourcing in your system? There are three primary benefits of event sourcing: it's evidentiary, it's recoverable, and it's insightful.
Unlike a database table where rows are updated with new values, events simply accumulate in an event log, providing the perfect evidentiary basis for a system. This is similar to the way that accountants perform double-entry bookkeeping, a method where no numbers are changed, ever. Instead, entries are always appended to the ledger. (You may have heard the old adage, "Accountants don't use erasers.") Accountants work this way because it's evidentiary: If a calculation goes wrong for whatever reason, they can always go back and figure out why.
Since it's append only, event sourcing is similar. You can look back in time at the event log and figure out what really happened or why things went wrong. This is a huge advantage when trying to figure out why a problem occurred or why a result has incorrect figures.
The second advantage of event sourcing is recovery through replayability, which is particularly important for data systems. Implementing a fix for a standard bug, like a formatting failure on a web application form, is generally a straightforward process: You change the code to fix the bug, and you ship. But data-related problems are often not so easy. If your service performs a computation such as calculating interest on an account and there is a bug in the computation, fixing the software likely isn't enough. There will be a significant number of accounts whose data has been corrupted as a result of the bug. Fortunately, with an event-based model, the problem is simple to fix: First fix the bug, then rewind back to a point before the bug surfaced, and replay the old events. Both the software and its resulting data are repaired in one go.
The final advantage of event sourcing comes as a result of its collecting detailed, event-level data: This data can be put to great use in analytics systems, whether for machine learning or for other types of analysis. Returning to the e-commerce example above, using events to represent the cart gives you an accurate, truthful record of the user's entire journey. This lets you solve useful problems that would be difficult to address otherwise. For example, you can use the data to figure out why people aren't buying much in your shop at a particular time or within a given category. This is in stark contrast to what a CRUD data model is capable of: simply representing the end state.
We will only share developer content and updates, including notifications when new content is added. We will never send you sales emails. 🙂 By subscribing, you understand we will process your personal information in accordance with our Privacy Statement.