Skip to content
BENIBIX Learn

Event Sourcing

Development🏗️ ArchitectureEvents and Messages

Also known as Event Store, Event Log

Save each change as an event. Build the present state from them.

Think of it like

Think of it like a bank statement. It lists each deposit and each spend. The balance is the sum.

Example

Jack's bank app stores each deposit and payment as an event. To show a balance, it adds them up. When a customer asks about a charge from March, it is all there.

Why it matters

You can see exactly how data got to where it is, which helps with audits and bug hunts.

Definition

Event sourcing stores every change to data as an event, not just the latest value. A shopping cart is saved as item added, item added, item removed, not as its final list. The current state is worked out by replaying the events in order. Nothing is ever written over. So you have the full history. The cost is more storage and more complex code.

Common mistake

Using it for simple data that nobody needs the history of. It adds a lot of work for little gain.

Key takeaways

  1. 1
    Store the changes. Not just the result.
  2. 2
    Replay to rebuild. State comes from events.
  3. 3
    Full history. Nothing overwritten.

Compare