vach
vach

Reputation: 11377

How to handle MixedQuery with CQRS?

In properly deisgned application it might be that you can separate all requests to commands (that only update aggregates and return void) and queries (that extract data from specific read optimized model).

But if you already have a heavy application and want to slowly move it to ES + CQRS path you might have requests that both modify and update models and return all the result (almost the same if you did a command and then query but that would be 2 requests) this is what i mean by mixed query.

I understand that this is clearly teoretical question and i dont have any code here to demonstrate it, but

how do you handle such a request with CQRS?

Upvotes: 1

Views: 517

Answers (2)

guillaume31
guillaume31

Reputation: 14070

It seems you're basically talking about sacrificing Command-Query Separation, which is a prerequisite to CQRS and an all-time good development practice anyway.

If I were to move to a CQRS approach, I'd start by conforming to CQS if anything, separating queries from commands just at a method level, before bringing in the whole CQRS apparatus.

You don't have to do it as a big bang rework, you can go functional slice by functional slice, making sure you have high-level automated tests to secure the refactorings.

Upvotes: 2

Alexey Zimarev
Alexey Zimarev

Reputation: 19640

Your "mixed query" is out of scope for CQRS. My answer would be - if you have this, you do not have CQRS. CQRS means commands and queries are segregated, this is the whole point.

You do not have to move everything to the new model immediately, you will have two parallel systems and move from one to another piece by piece. I would strongly not recommend mixing old stuff into the new model.

Upvotes: 3

Related Questions