Event Sourcing in 1665
The interest in event sourcing is slowly increasing, and after I learned about it at Laracon Online I went out to read and watch more about this design pattern. Since the best way to really know something is to explain it, I came up with a - in my mind - funny example: admirals and pirates!
Introducting the main characters
The year is 1665, and the Republic of the Seven United Netherlands is at war with England. Michiel de Ruyter is commander of the Dutch fleet after an already successful career as merchant and pirate fighter. He succeeded in winning several high-stake battles but ultimately died on what became his last tour.
In roughly the same time period the pirate named Blackbeard is roaming the Caribbean, privateering and plundering towns and ships. Like De Ruyter he captured or destroyed plenty of ships, but in his case it made him rather infamous and after a little more than a year he was killed.
Let us start with the pirate, Blackbeard. He keeps track of where the treasure is, and possibly the position of the ship. What counts in the end is the amount of gold and rum on board. In a typical application you might for example store in the database how many posts a user has. The likelihood of walking through the entire process of writing one of those posts again is very low.
Michiel De Ruyter
In contrast, Michiel de Ruyter has been tasked by his principals (whether the Republic or merchants) to keep track of everything he comes across and anything that happens. Written down in logbooks, this information was worth its weight in gold. Imagine maintaining the systems for a rum distillery. You have created a so-so batch and would like to improve the next one. For that, you are thinking of tweaking one of the distilling machinery. However, for this next attempt you would not need the existing casks of rum, but the recipe that lead to it. In terms of event sourcing this would mean storing all steps of the distilling process in a database, and after tweaking the machine you could reapply (replay) those steps (events) and give the new outcome a taste.
~~Michiel De Ruyter~~ Event sourcing
With event sourcing the developer is just like Michiel de Ruyter keeping track not only of where the cargo is, but also how it got there and what the journey was that led to the cargo. In principle, another admiral could take the logbooks and redo the same journey in relative safety. For a pirate this would make much less sense, since there is only one treasure buried at the X and when it's gone it doesn't make sense for someone else to return there.
While one might argue the morals of Blackbeard, the developer not practising event sourcing is not lesser to the one that does. It all depends on the client and the kind of the expedition. That being said, happy sailing! :)
On a final note, enjoy this trailer for a - perhaps a bit chauvinistic - movie about Michiel de Ruyter: