Laravel Event Sourcing
In an application, we store the state of the application in the database. When the state changes, we update the state. By doing this, we lost the previous state. We don’t know what lead to the current state.
Let us consider an example. Imagine we have a bank with customers having accounts. When a transaction happens we either increment or decrement the balance in the account. In this scenario, we know the latest updated balance but we do not know which transaction leads to that balance.
To solve these kinds of problems, the event sourcing comes in handy.
When using event sourcing you’ll take a different approach. All changes to application state are stored as a series of events. The key benefit here is that you now have a history of your database. From which we can calculate the balance of the last year or a report based on those sourced events.
To make use of the event sourcing, there is this interesting package — Laravel Event Projector.
Also, there is a document on how this Laravel event projector works.
Hope this helps to build an interesting application which can make use of Laravel event sourcing.
Thanks for Reading!!.