It is a pattern that adds dimension of time into the data model. This helps with documentation of every change in aggregate’s lifecycle and helps to retrieve information about the previous state of it; event sourcing pattern uses audit-logs and data is immutable. It uses event store to persist the events. Quite commonly used in finance as a ledger or in retail, logistics, healthcare, retail, transport and even video game development.
Operations
A typical flow is as follows
- Load the aggregate’s domain events
- Reconstitute a state representation and present in a state that can be used to make business decisions
- execute aggregate’s command
- produce new Domain Event
- commit the new Domain Event to Event Store
Advantages
- Allows you to restore all previous states of the aggregates as well as the current state
- it provides with a consistent audit log of everything that happens to the aggregate’s state
- When the data is in a stale state, it raises an exception
- it allows you time time travel and move backwards and forwards in time which is valuable for debugging and analysis
- Allows to subscribe to changes that happen within a domain
Disadvantages
- The learning curve is sharp and requires changing the way you think about managing data. Your team may require training and time to get used to it
- Add architectural complexity due to moving parts within the system
- Not easy to make changes to a model because events are immutable
- It is resource heavy; it gets slower after awhile so certain caching methods, such as snapshot may have to be implemented at a certain point