Our journey into microservices has led our teams to think more about building highly available and resilient software. A lot of this has been related to how we identify with the concept of the state. In most systems, a state is always tied to the database and losing this data would mean losing all information about the state system. Replication and snapshotting have been our solutions to ensure we don’t lose data in any way.
Event sourcing provides an interestingly different approach to viewing the state of the system. Event sourcing forces us to think in terms of events – events that affect the state of the system.
Systems that use event sourcing focus on recording events that affect the system in some kind of a datastore. This could even be a file. The state of the system is then generated by running through these events and using the relevant processors to operate on the data to generate the state of the system, thus allowing us to rebuild the state of the system in case our database goes down. This opens up a world of opportunities for making data/systems more resilient as long as the events have been safely stored.
CQRS stands for Command Query Responsibility Segregation. A command is a request that modifies the state of the system while a query is a request that queries the state of the system without changing the state. The data store that houses the events generally keeps track of whether a request is a “command” or “query”.
However, event sourcing is not a new concept and has been around for years and is well documented by Microsoft
. Though the pattern has been usually popular with financial systems it’s definitely beneficial to every kind of system. If you’ve ever been intrigued by how banks ensure they don’t lose details of your transactions and don’t have to be worried about losing their primary database, the answer is usually event sourcing. Greg Young
, is an entrepreneur and engineer who has championed the cause of making event sourcing more accessible to all businesses through theEventStore
Last Friday, Raza walked the micro services meetup group, in Pune, through the benefits of working with an event sourced system. If this interests you, feel free to reach out to our engineering teams in Pune or Mumbai on how event sourcing can be beneficial to you. If you’re interested in contributing to an open sourced project on event sourcing have a look at http://github.com/supersid/Zuleikha_es