remi bourgarel
remi bourgarel

Reputation: 9389

Is CQRS tied up to Event Sourcing?

I recently read a lot about CQRS and for me it seems like it's closely tied up to Event Sourcing.

But like this answer said https://stackoverflow.com/a/9217461/277067 For me Event SOurcing seems a bit too complicated/scary for a beginners like me ("what ? my object current state is nto stored anywhere ??").

So i'd like to know if indeed they are tied up or if there is any tools/famework that would help for doing cqrs (event observer, command handler) without the complicated part of event sourcing.

Thanks

Upvotes: 4

Views: 703

Answers (5)

lokanadham100
lokanadham100

Reputation: 1283

CQRS and EventSourcing are independent of each other. But based on requirement, we can combine them achieve great result.

Lets take some examples:

CQRS (with out event sourcing):

  1. Ecommerce load balancer: Mostly all requests to ecommerce website are get requests, where user will browse through the available products. And there are sellers who will update these products and related information, but will do less frequently but in bulk. This seller requests can be served from one server and user requests can be served from other servers. Both these servers are fetching/updating data from same DB(single point of source). Here there is no event sourcing. But we are able to split the read & write at load balancer level.

  2. Database master/slave: Some times we can use slave to handle read requests if database throughput is high. Here again we are able to split read & write logic without event sourcing.

EventSourcing(with out CQRS):

  1. Ecommerce callbacks: Lets say you want to send a mail/notification to customer regarding order confirmation or cancellation after an order state change. Here we can create an event after order state change and all the subscribers listening to that event will consume these events. In our example mail/notification class will listen to this event and will immediately send mail or notif. Here there is no CQRS involved.

Upvotes: 0

Alireza Rahmani Khalili
Alireza Rahmani Khalili

Reputation: 2954

in a short answer, I should say: we can have CQRS without event sourcing. but we can not have event sourcing without CQRS. in general, we have 3 type of CQRS: standard, event sourcing, and eventual consistency.

Upvotes: 0

Golo Roden
Golo Roden

Reputation: 150982

Short answer: No, CQRS and event-sourcing are not tied to each other.

Long answer: No, CQRS and event-sourcing are not tied to each other, and they aren't tied as well to domain-driven design (DDD).

If you want to define what CQRS, event-sourcing and DDD are in a few words, you may come up with explanations as the following ones (yes of course, they are over-simplified, but that's exactly the point here):

  • CQRS is a design pattern that separates writing state from reading state (commands vs queries).
  • Event-sourcing is a way to store data in a database, where the deltas are stored rather than the actual state.
  • DDD is a method to make communication on the domain easier within interdisciplinary teams.

Each of them works without the others very well. E.g., you can model a domain using DDD, and then implement it without CQRS or event-sourcing. You may also do event-sourcing without ever needing DDD or CQRS. And so on…

But: The three concepts play very well together, which is why they are often called together within a single sentence. So, no they aren't tied to each other, but they make a lot of sense in combination with each other.

The following picture shows how they may interact with each other:

CQRS, event-sourcing and DDD in combination

(The image is taken from the documentation of wolkenkit, a CQRS and event-sourcing framework for JavaScript and Node.js.)

  • CQRS describes that you send commands to the write model, and that you receive events and subscribe to queries from the read model.
  • Event-sourcing is used with the write model to store the events that are published as result of the commands the client sends.
  • DDD is used within the write model to turn commands into events and to run the appropriate logic.

Upvotes: 3

Sudarshan
Sudarshan

Reputation: 8664

No they are not tied up IMO, you can find my rationale to a related question here

Upvotes: 0

Alex Shkor
Alex Shkor

Reputation: 1209

You can use CQRS without Event Sourcing. In command handler you are using some Repository to get or save last state of aggregate root. Just implement simple Repository, wich will save and load state straight from database.

Upvotes: 1

Related Questions