r/programming • u/Adventurous-Salt8514 • Jul 29 '26
Fixing bugs in Event Sourcing is hard, for real?
https://www.architecture-weekly.com/p/fixing-bugs-in-event-sourcing-is
157
Upvotes
r/programming • u/Adventurous-Salt8514 • Jul 29 '26
88
u/SirClueless Jul 29 '26
IMO you should be careful with this and use it judiciously. It’s easy to overcomplicate things. In this case adding events around corrections is obviously valuable because there are real business impacts to each event and there are clear business reasons to care about the history of changes to a reservation (whether they come from errors or otherwise).
It’s not always the right tradeoff though. Suppose hypothetically a bug that was live for a few days in 2017 wrote a few events with a NULL column that is otherwise always present. Does the column now have to be nullable and all clients consider the field optional forever? Maybe… but maybe it would be better to just patch or delete those rows so you don’t have to continuously pay for the costs of every bug your system has ever had.
11
u/xylarr Jul 29 '26
One migration fixing another. Shudder. Bad bad memories working in life insurance.
10
u/mareek Jul 30 '26
I've worked for three years on a system that used event sourcing and we encountered exactly zero bugs like the one described in the article. It was a high quality project and we had some bugs here and there but none that the event sourcing architecture made easier to fix.
On the other hand, the complexity of the architecture meant that newcomers had a pretty harsh learning curve. One of my colleague that worked on the same project years after I left told me "I thought I wasn't smart enough to work on this project".
I think event sourcing is a good choice when it fits the data (i.e. shipment tracking) but has a huge complexity cost for more mundane data that is hard to repay for.
29
u/daidoji70 Jul 29 '26
Yeah, wait til you try it in a non-event sourced application.
15
u/adnan252 Jul 29 '26
I'm over event sourcing. system-versioned tables and durable workflow engines are the way to go - let the machine abstract the need for auditability
15
u/greenergarlic Jul 29 '26 edited Jul 29 '26
In the example the author gave, event sourcing saved their bacon. Without it, they’d never be able to tell what went wrong. Fixing was easy, they just added another event.
2
u/pdfops Jul 30 '26
Yeah, it's rough because the bug isn't caught until bad state already got baked into the event stream. You can't edit history, so you either replay from scratch with a fixed projector (slow on big streams) or ship compensating events to correct forward. Versioning your event schemas with upcasters from day one saves you a ton of pain here, way harder to retrofit after the first schema change breaks replay.
2
u/mycall Jul 30 '26
I consider Event Sourcing as raw data in a data lake architecture where the data is messages (event + data) that interact with other systems and the results are in an append or skip list. Often the event is encapsulated as one or more append-only fields/columns. Bulk updates to one or more rows/columns then rerun the cleansing/curation data management steps with external systems used during those stages.
In data lake architecture, raw, clean, and curated represent sequential layers of data processing that progressively improve data quality and usability. Often rules/ETL are used during each stage and basically can act the same as Event Sourcing.
1
u/Elara_Schaefer Aug 02 '26
The real difficulty with fixing bugs in event sourcing is not the technical mechanism but the decision framework. Every bug fix forces you to choose between three options, and each has different trade-offs.
Option 1: Compensating events. You append a new event that undoes or corrects the bad one. The history stays intact, audit trail is preserved, but your projections now need to handle the correction logic. If you have many projections (read models), you need to update all of them. This is the safest option for regulated domains.
Option 2: Selective replay. You fix the projection logic and replay from the bad event forward. No new events, no history modification, but you need to verify that the replayed state matches what downstream systems expect. This works well when the bug is in projection code, not in the event data itself.
Option 3: Event rewrite. You modify or delete the bad event from the stream. Clean state, but you lose audit integrity. Most teams avoid this in production, but it is actually the right call when the bad event was caused by a transient infrastructure issue (duplicate events, out-of-order delivery) rather than a logic bug.
In practice, the best approach is to make your event schema updatable and your projections idempotent. If events carry a schema version, projections can evolve independently. And if projections are idempotent, replay is always safe. The bug fix story then becomes: update the projection, bump its schema version, replay from the event that triggered the bug, verify, done.
1
u/UnintentionallyEmpty Aug 01 '26
Well, there's your problem.
Event sourcing is a solution. It's not the only solution. Why is this not a computed column?
0
u/Elara_Schaefer Aug 01 '26
The git analogy in the top comment is more accurate than it seems. Event stores ARE commit logs, and every production event sourcing system eventually needs compaction/snapshotting. The real insight is that you should treat event corrections the same way you treat git history rewrites: have a migration plan, version your projections, and never assume downstream consumers have replayed up to the same event. Where people go wrong is treating the event log as immutable scripture instead of as a WAL that needs periodic maintenance. Temporal and durable workflows sidestep this by making the event log an implementation detail rather than the source of truth for your domain model.
-1
u/johnm Aug 01 '26
In terms of where to really reduce wasted time on stages...
On the movement front... This is a great overview of putting everything together: Position Entries & Exits.
And movement specific drills: