I implement Event Sourcing and CQRS pattern in my application. I inspired by CQRS journey where I downloaded sample code. There I found whole infrastructure for Event sourcing (CommandHandlers, EventHandlers, Events, Envelopes ... etc.), but it is quite big amount of code and I can't imagine that I need all of code for my simple Event sourcing.
Do you know some common tested library/nuget package/project containing all infrastructure for sending/registering commands, events and everything what I need in Event sourcing pattern? Or should I implement it by myself?
Event sourcing persists the state of a business entity such an Order or a Customer 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. Since saving an event is a single operation, it is inherently atomic.
CQRS is implemented by a separation of responsibilities between commands and queries, and event sourcing is implemented by using the sequence of events to track changes in data.
How it Works. The fundamental idea of Event Sourcing is that of ensuring every change to the state of an application is captured in an event object, and that these event objects are themselves stored in the sequence they were applied for the same lifetime as the application state itself.
On the technical level, event sourcing can be implemented using dedicated storage systems, as well as general-purpose "NoSQL" and SQL databases. If you're interested in the origins of event sourcing, the articles by Greg Young on event sourcing and CQRS are a great place to start.
May I introduce this .NET Core 2.x based event sourcing framework: https://github.com/jacqueskang/EventSourcing/
It provides base classes for implementing events, event-sourced entities, entity repositories, and several simple event stores to persist events in text file or in database (using EF Core).
It's especially easy to be integrated in a ASP.NET Core web application, I have a pretty simple demo here.
Welcome any contribution or comments!
The general recommendation is to not write your own event store. Sure, you can write your own ES, but do it only for educational purposes. For production systems I would recommend you to use an existing ES. It might look like a lot of unnecessary infrastructure code at first but you will soon notice that you do need it. In its simplest form ES is not that hard but once you start dealing with concurrency, performance etc it will be more complicated.
NEventStore and Event Store are two well known event stores.
As a side note from my own experience, do not underestimate the time that you will need to invest on infrastructure code even if you use an existing ES.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With