Winemaking with Mutable Event Sourcing in Django
Have you ever been drinking a glass of wine and wondered how it was made? Creating an amazing bottle of wine is a fascinating process involving equal parts farming, art, science and a dash of luck. Every year during harvest season, winemaking teams scramble to harvest the best fruit, press it to juice, ferment it, and prepare it for aging. It can require teams of people and around the clock work during harvest. Even after harvest, it may still be years of blending and aging before the finished wine ends up in a bottle on the shelf of a store. It is a lot of coordination and effort, and winemakers need to be able to review all of the steps they have taken thus far in making the wine so that they can plan for the next steps. This is where software comes into play.
Event sourcing is a powerful architectural pattern where the state of an object is defined by the sequence of events that have occurred to it. In our system, events are tied directly to meaningful user actions: instead of generic updates like "wine updated," we record specific events like "volume transferred" or "blended with another lot." These events are stored in chronological order in what’s called an event stream.
A key tenet of event sourcing is that events are immutable. Once something has been documented as happening, then it always happened. Most commonly, to fix a mistake in the system, another event is recorded at the end of the event stream that registers the necessary correction, as opposed to altering the original event.
The idea of an immutable event stream didn't work for us at InnoVint, but everything else about event sourcing ticked all the boxes. So we set out to reimagine event sourcing to allow our users to alter the past, allowing the implications of the edit to flow through everything after it. In this talk, we'll work through how this mutable event system is implemented using the Django ORM and how our developers interact with the event stream to build complex user behaviors.
Outline
-
Provide a high level introduction to the winemaking process and why it makes such an exciting domain for software development.
-
Introduce event sourcing using domain driven design.
-
Dig into why the winemaking process is difficult to model using standard, immutable event sourcing.
-
Present the idea of "actions" as persisted and editable, user-defined commands representing complex real world behaviors.
-
Show how these actions can be directly linked into an event stream to allow rewriting the history of the event stream.
-
Demonstrate how a unit-of-work decorator and domain driven aggregates populate the event stream.
-
Putting the pieces together, work through an example of how a user can interact with an example application to track, and correct, the steps in making their wine.
This talk is ideal for developers who are already comfortable with Django and are interested in ways to expand its capabilities.