Firstly, the main drivers of this i.e. Greg Young/Udi Dahan/Particular are trying to sell a product and consultancy. While there is nothing wrong with this, there is a significant cost and the motivation to use this architecture is marketing driven rather than logical gains. Make sure it is appropriate for your organisation. 95% of organisations it probably isn't. It wasn't for ours but overzealous architecture proponents bought the marketing.
The cognitive load is immense compared to a smaller system architecture. Every change results in masses of friction, cost and time. Your agility will be destroyed pretty quickly. Also due to the cross-cutting concerns, there is no escape from it other than to port everything away.
The products to support it are generally immature, low quality and opinionated to the point that it's impossible to integrate cleanly on anything but a greenfield. Expect friction.
There are better gains to be had from changing your architecture to a purely service model (I hate the term, but microservices) and skip the whole concept.
However if there's one thing I have learned that Command-Query Separation is a good model for isolation. The Event Sourcing bit, not so much.
I found the cognitive load to be less than with other service based architectures I have worked on. I could jump into any area of the code base and because of the naming conventions for commands and events I could see what was going on - this has never been my experience with a service oriented architecture.
The main change in developer thinking that is necessary is that you don't record state you record state transitions. Once that is internalised development is easy, a new feature requires new commands and handlers, new events, new queries and an updates to aggregates.
I had absolutely no problem with cross cutting concerns - security for example was handled in command handlers where needed. Other system components of our system that didn't use CQRS - for example reporting, general ledger, third party integrations - received data from the event stream and injected commands back into the system. So in no way was our organisation infected by CQRS / ES.
The cognitive load is the same as any distributed system. It adds massive complexity. If the surface of your application is a SaaS system it is far simpler to deploy hundreds of small tightly coupled instances than to scale it up to one massive instance architecturally.
I really do loath the acronyms.
I like to pronounce CQRS as "suckers". Though I find utility in the concept itself :)
I'm currently dealing with a proverbial balls up which is the outcome of an inappropriate application of CQRS and then microservices architecture fads. They have packer, vagrant, ansible, AWS, all sorts of random things half-plugged into a .net solution. Which makes little sense as this is a Microsoft shop who owns their own paid up datacentre estate and it's a monolithic project that doesn't suit this model nor justify the cost of conversion.
Let me clarify fad here: these architectures work well for specific cases like netflix, amazon and other flag waving success stories but not for general cases like standard LOB stuff.
One is the idea that commands are write-only (they are not allowed to return information). The reason for this restriction is fairly unclear, and there are several pieces of information that I believe can be legitimately returned:
- Has the command finished executing?
- Was it successful? If not, what was the exception thrown?
- If the command created something, what is that thing's identifier?
- For distributed systems, what is a vector clock after the command's execution?
Another idea is aggregates, especially the fact that each event is bound to a single aggregate and that two aggregates process their associated events independently. I can see how this can be useful, in a NoSQL-ish kind of way: by sacrificing the ability to enforce invariants across multiple aggregates, it becomes trivial to distribute event streams, to quickly compute the state of a single aggregate among millions, and to write to several aggregates in parallel without a global lock.
Still, sacrificing those invariants is costly. Many domains will have constraints on uniqueness (e.g. each e-mail address may belong to only one user) or relationship arity (e.g. each student may have at most one internship, each internship may have at most one student), and from my experience, expressing those constraints in an aggregate-based system usually ends up in:
- creating a "lock" aggregate with "Locked" and "Unlocked" events, or
- ignoring constraints and providing an user interface to manually resolve violations.
I would rather express simple constraints with simple code and have to work hard for optimizations later, than to have to write complex code just to solve an unconfirmed performance issue.