Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event sourcing without CQRS

I know that CQRS can be implemented with or without event sourcing, but does it work the other side? Does event sourcing without CQRS make sense? If so, how it should be implemented?

like image 416
k13i Avatar asked Jul 03 '18 17:07

k13i


People also ask

Does CQRS need Event Sourcing?

The current state of the system is determined by processing the events. You may store that result, but only as a cached value, not as the source of truth. Both these patterns are useful, but they do solve different challenges. CQRS is much more common and doesn't need Event Sourcing.

What is the difference between CQRS and Event Sourcing?

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.

Which database is best for Event Sourcing?

The core features such as guaranteed writes, concurrency model, granular stream and stream APIs make EventStoreDB the best choice for event-sourced systems - especially when compared with other database solutions originally built for other purposes, And on top of that, it's open source.

What is the difference between event-driven and Event Sourcing?

As you may have already concluded, event-sourcing involves using events to persist the data changes. In contrast, event-driven architecture is about communicating events with data changes between service boundaries. This means that they solve different problems in a particular landscape.


3 Answers

Yes, it does.

Basically, the entire idea of event-sourcing is just to store the changes that led to the current state, instead of storing the current state. This way, with event-sourcing, you automatically have a history and can run time-series analysis on your data, and try to learn from the past.

Whether you use CQRS is a completely different story: CQRS is about separating the writing to your application from reading from it.

In the same way you can use CQRS without event-sourcing, you can use event-sourcing without CQRS. Both are independent of each other, they just accidentally fit each other very well.

like image 112
Golo Roden Avatar answered Sep 22 '22 03:09

Golo Roden


CQRS is about separating the reads from the writes. Write operations need things like locking, guaranteed order, and always the latest state. In classical systems (relational databases) you would also give this guarantees to read operations, which comes with a huge performance impact and big issues when it comes to scalability. That's why in CQRS you give read operations a separate copy of the data which is optimized for fast reads, e.g. it is denormalized and put into more efficient, faster systems (e.g. a memory cache), I'd call this a "read view [on the system's data]".

CQRS works without ES, because you can create the optimized read view from a traditional data store (e.g. a relational database).

ES does work without CQRS, but only if the number of events is reasonably small. Because you are storing all the changes of the system in a database and every read has to use the same database and iterate over all events that it needs to fulfill the query. Eventually there will be too many events that need to be read in order to answer and the time it takes to answer will become too long.

like image 42
coderbyheart Avatar answered Sep 23 '22 03:09

coderbyheart


I've yet to see a situation where you use ES without CQRS because this would only be the case if you do not need any query/analyses capabilities across more than 1 entity. 99% of all cases this is a requirement ;)

You will definately need something like CQRS if you want to query over multiple entities as you will apply a different way of querying your data other than using event sourcing. (unless you want to replay all events every time you query..) How you go about implementing the CQRS part isn't set in stone though. It just describes reading and writing are 2 seperate concerns handled in different ways.

So in general: No, this does not make any sense.

like image 25
Vincent Hendriks Avatar answered Sep 23 '22 03:09

Vincent Hendriks