Event Sourcing

1. What exactly is Event Sourcing?

A Claims service stores each claim's status as a single row in Azure SQL Database, overwritten every time the status changes.

Now a bug briefly assigns the wrong status to thousands of claims overnight. Because each row only ever held the latest value, there's no record of what the status even was before the bug ran.

When only the latest state is kept, a bad update doesn't just cause damage, it erases the evidence of what was true before it. That's exactly what event sourcing prevents.

2. How would you fix it in .NET/Azure?

Event sourcing keeps every version instead of just the latest: record every status change as a new event, instead of overwriting a single row, and store each event as an appended document in Azure Cosmos DB. You then calculate a claim's current status by replaying its events in order, so nothing already recorded is ever erased or overwritten, including the moment a bad update happened.

Use: Azure Cosmos DB (Change Feed)

Keep every change that happened, not just the answer it left behind.

3. How can you visualize it in everyday terms?

A bank balance printed on a card only shows one number, today's balance, and overwrites it every time you check again.

A checkbook register instead keeps a line for every deposit and withdrawal, in order. You can always work out what the balance was on any past date just by adding up the lines up to that point.

A single overwritten balance can't tell you what went wrong or when. A register that keeps every line always can.