AxonIQ heeft dit gerepost
Event Sourcing "Friday FUD": One challenge of Event Sourcing is that I can't change historical data. Or can I? The short story is simple: you can. But you might get in trouble, and it's not because of Event Sourcing. One of the things I love most about event sourcing is that it forces people (not only developers) to think in terms of messages—little nuggets of information that flow between components in a system. Some of these nuggets describe something from the past and hence are stored for longer. To make these information streams reliable, we use them directly to drive decisions in our system. The main point here is these nuggets of information that flow between components in a system. Whether we use Event Sourcing or not, once information is shared between systems, we should be extremely cautious when changing it. There is an assumption that because Event Stores are append-only storages, it's impossible to change their contents in other ways than appending more data. While that might be true for some specific implementations, it's not a general rule. At AxonIQ, the event store is part of Axon Server. We have a feature to transform the stream of events. 🤔 So I can change the data in historical events! That's great. Update queries for the win! Well, no. Coming back to the nuggets of information flowing between components, you shouldn't. If you change something in the past, the other systems won't be notified of this change. As a result, you have eventually reached a state of inconsistency. 🤔 If change is bad, why have a feature to change historic events? Not all changes are equal. As long as a change doesn't modify an event's semantics—its meaning—it is no problem to change it. We're only changing the representation of the same "nugget of information." These changes can happen for several reasons. Schemas may evolve, requiring you to change the representation of certain messages. Privacy regulation may also require removing information stored in your historical events. While there are different strategies to deal with these changes, altering the data should not be discarded as an option simply because event sourcing is advertised as append-only. But make sure to look at alternative solutions as well. Event Sourcing comes with many ways to address these issues. 🤔 But what if we need to change an event's semantic meaning? Don't. Changing that will change the story you've already shared with other systems or components. This is where Event Sourcing's strength comes in: fix forward. Make corrections by appending new events. These will then travel around your system like any others, fixing the "story" in downstream components as well. And yes, the fact that it happened will remain visible in the event store. So be it... Interestingly, the inability to change data is attributed to Event Sourcing, while it's actually Event Sourcing that provides better ways to deal with the situations that require it.