Event sourcing and persistence

event-sourcing

I'm reading up on event sourcing and have a question regarding persistence.

I can still have a DB with all entities, right? Or should the events be replayed every time the application is started to get the latest version of each entity in the memory? Seems like a waste on larger systems (as in large amount of data)?

The point with event sourcing is that I can can replay the events to populate a data store if required? (or analyze the data)

Best Answer

You will benefit the most from the event sourcing when you decide to change your system architecture also. Going towards a CQRS style architecture combined with DDD will bring up the true benefits of an event sourcing, at least in my opinion.

Building an event store that behaves well in large systems is not an easy task indeed. Replaying all the data might be expensive indeed, depends a lot on the amount of data that needs to be replayed. But there are techniques that might help you with this, one of them being the concept of a snapshot. The replay is done only from a certain point forward. The advantages that an event store bring into your system are invaluable. Having everything that happened in your system replay-able, all the data in every moment is a great thing. Think about analysis, about bug reproduction, about statistics.

There are a lot of great event stores, the last one was just released yesterday Event Store and it seems like a really good one.

The traditional database can be kept for the query part of your system to build up DTO's with the requested data. This database can be organized and optimized considering the query needs of your application and clients.

I wrote a detailed article about what are the benefits and how does a CQRS architecture combined with event sourcing really looks like. You can check it out CQRS, Domain Events and DDD review.