Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

DDD/CQRS Querying Events

I was looking at post's on querying in application designed with approach Event Sourcing/DDD/CQRS.

As I understand events are changes to the state of a domain object. The changes to state will be maintained as history/events in DB(any of sql/no sql).

If user wants to query to get current state for a particular aggregate root, it will involve fetching history of events.

When user will query especially business specific queries he/she will be interested in current state not the history of events.

How querying or 'Q' part in CQRS works with event sourcing?

Consider I have a domain object "Account" as aggregate root. The account AR will go through lots of changes i.e. credits debits. event store will have credit and debit events.

Consider user is required to get current balance of an account, how stream of history of events will suite here? How will user fetch current balance for given account?

I am unable to understand, How for business specific querying history of events will be useful?

-Prakhyat M M

like image 655
Prakhyat Avatar asked Aug 28 '14 07:08

Prakhyat


People also ask

What is CQRS and DDD?

As you know Event Sourcing, CQRS (Command Query Responsibility Segregation) and DDD (Domain Driven Design) trend microservices topics.

Do you need event sourcing with CQRS?

CQRS + Event Sourcing Both patterns are frequently grouped together. Applying Event Sourcing on top of CQRS means persisting each event on the write part of our application. Then the read part is derived from the sequence of events. In my opinion, Event Sourcing is not required when we implement CQRS.

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.

What is the difference between CQS and CQRS?

CQRS takes the defining principle of CQS and extends it to specific objects within a system, one retrieving data and one modifying data. CQRS is the broader architectural pattern, and CQS is the general principle of behaviour.


1 Answers

I would recommend you to read more articles from Greg Young (He is like the father of CQRS and Event Sourcing), like this: CQRS, Task Based UIs, Event Sourcing... agh.

Sorry for my bad English, I am from Paraguay. But I really like DDD - CQRS - ES and I would like to try to make a point.

The use of "Projections" (also known as Materialized Views) and the concept of "Eventual Consistency" are the fundamentals that every practitioner of CQRS should understand very well. The Event Store is for query. Is in the Command side of CQRS, not the in the Query side. You may use a bus to send the events stored in the Event Store to the query side in order to process and generate a read model, or view models, from which you can query. In any case a eventstore per se is a query model.

Looks like you are a Java guy, but, still, you may want to check the CQRS Journey from Microsoft. Hope this helps a little bit and motivates you to do more research on DDD / CQRS / ES, the New Trio of Line of Business Applications.

like image 168
Narvalex Avatar answered Sep 23 '22 06:09

Narvalex