Description
Event Sourcing stores the state of a business entity as a sequence of state-changing events. Whenever the state of a business entity changes, a new event is appended to the list of events. The current state is reconstructed by replaying the events.
Where to use
- Audit logging and compliance. \n
- Financial ledgers and accounting systems. \n
- Complex domains where history is important (DDD).
Real World Example
A Bank Account. Instead of storing 'Balance: 100', we store [Deposited 50, Withdrew 10, Deposited 60]. The balance is calculated on the fly.
Code Example
# Code Concept for Event Sourcing
# This pattern is architectural.
class Service:
def execute(self):
# Implementation logic
pass
