CQRS – Compatibility with Hexagonal Architecture

cqrs

I am beginning a project and I was wondering If I can use CQRS and Hexagonal architecture in the same project, or in fact they are incompatible.

I read about CQRS and some people agree that it is not an architecture, and more like a pattern.

What do you think?

Best Answer

This is like asking if you can use utensils to eat ice cream. (Yes you can. I recommend a spoon.)

CQRS asks you not to mix together the complexity needed to perform queries with the complexity needed to update.

enter image description here

Hexagonal Architecture asks you not to mix the complexity of your input and output ports with your central application logic.

enter image description here

So yes you can do both. But doing one doesn't mean you've done the other.

If you did, it could be diagrammed like this:

enter image description here

That shows where things go. Imagine adapters between the hexes that help isolate the central application logic from DB and UI changes.

Many of these fancy principles are really just about isolating things. It's not that you can't make something that works if you ignore them. But following them means the impact of a requirements change is isolated. It doesn't make it easier to write the code nearly as much as it makes it easier to maintain the code.

Hexagonal, onion, and clean architecture all seem to be different names for the same thing. Authors love to steal an idea and give it a new name.

Related Topic