Event Sourcing in Python — ELI5
Think about your bank account. The bank does not just store your current balance. It stores every single transaction: deposits, withdrawals, transfers, fees. If you want to know your balance, the bank can add up all those transactions from the beginning.
That list of transactions is your history. And because the bank keeps it, you can answer questions like “What was my balance on March 1st?” or “Show me all the deposits from last month.”
Event Sourcing works the same way for software. Instead of saving just the current state of something (like “the order is shipped”), you save every event that ever happened to it:
- Order was created
- Item was added
- Payment was received
- Order was shipped
To know the current state, you replay those events from the beginning. To know the state at any point in the past, you replay events up to that moment.
Why not just save the current state? Because you lose history. If all you know is “the order is shipped,” you cannot answer “when was the payment received?” or “was an item removed and re-added?”
Event sourcing is like keeping a diary instead of just a snapshot. The diary tells the full story. The snapshot only tells you where things stand right now.
Most apps do not need this. But for banking, auditing, logistics, and anything where knowing the full history matters, event sourcing is incredibly powerful.
The one thing to remember: Event Sourcing saves every change as an event so you always have a complete, replayable history — not just a snapshot of where things are now.
See Also
- Python Aggregate Pattern Why grouping related objects under a single gatekeeper prevents data chaos in your Python application.
- Python Bounded Contexts Why the same word means different things in different parts of your code — and why that is perfectly fine.
- Python Bulkhead Pattern Why smart Python apps put walls between their parts — like a ship that stays afloat even with a hole in the hull.
- Python Circuit Breaker Pattern How a circuit breaker saves your app from crashing — explained with a home electrical fuse analogy.
- Python Clean Architecture Why your Python app should look like an onion — and how that saves you from painful rewrites.