News for hackers. Stuff that matters.
Re:CQRS: Command Query Responsibility Segregation (2011) by Sodman on Wednesday November 11, 2020 @09:25AM (#25058624)
The biggest drawback I've seen to CQRS - particularly in an event driven architecture - has been increased complexity, usually in exchange for increased scalability. I'm a big fan of "Do the simplest thing that could possibly work" so I'm mostly opposed to CQRS except for some niche cases. A CRUD design for an app can scale well enough for most businesses to get into very decent revenue numbers. When you start bumping up against limitations, then you can start to refactor. Until then, the simplicity of a CRUD app can let you prototype and ship faster, as well as significantly boost new dev onboarding time.
Re:CQRS: Command Query Responsibility Segregation (2011) by kemiller2002 on Wednesday November 11, 2020 @10:59AM (#25059405)
It is amazing how much a well tuned and properly functioning database can handle. At my last job, this was a huge hurdle I was tasked with handling. They're CQRSish design slowed so many things down through needless complication or hidden inefficiencies. People always jump to "we need to scale and this will make it faster" when the real answer is often, "how about we focus on some fundamentals and just make our code more efficient"
Re:CQRS: Command Query Responsibility Segregation (2011) by barumi on Wednesday November 11, 2020 @11:30AM (#25059735)
> The biggest drawback I've seen to CQRS - particularly in an event driven architecture - has been increased complexity, usually in exchange for increased scalability.

I fail to see how CQRS is a factor in increased complexity. After all, CQRS boils down to separating the interfaces for queries/reads/immutable operations and commands/writes/mutable operations. Unless you're bolting on unrelated concepts, like event sourcing, then CQRS is not a significant source of increased complexity in non-trivial applications.

Can you shine some light on which aspects led to higher complexity in your use of CQRS?

Re:CQRS: Command Query Responsibility Segregation (2011) by hn_throwaway_99 on Wednesday November 11, 2020 @11:50AM (#25060000)
I think the issue really is that when people talk about CQRS they are almost always talking about event sourcing + CQRS, and that's where the complexity lies.

I mean, look at GraphQL, which essentially makes it trivial to implement "plain" CQRS because there are always explicitly separate operations for mutations and queries, and it's easy to have separate object definitions for these operations (this is in direct contrast to many REST architectures, where your verbs - GET, PUT, POST, DELETE, etc. - are fundamentally operating on the same objects). However, underlying in the actual DB there is just a single representation.

But I think when people talk about CQRS these days they are really talking about the underlying data being different (e.g. a log of write operations vs a repository of queryable objects), and that usually implies something like event sourcing, and with that model you have a ton of complexity involved in keeping the different "sides" in sync, and since many update operations also involve queries (i.e. only do this update if something else is true about another object) you get into transactional difficulties as well.

Re:CQRS: Command Query Responsibility Segregation (2011) by Sodman on Wednesday November 11, 2020 @12:49PM (#25060723)
Correct, this is what I meant. Even though they're technically different concepts, I've found in practice they're almost always coupled together.

FWIW, these days I usually do go with GraphQL over REST in my APIs, partially due to some of the advantages you get from separating the queries and mutations. But like you said, I prefer to ultimately store the info in a DB in one consistent format unless it's absolutely unavoidable. Sometimes it is unavoidable, but like the article mentions you can frequently get away with having a "Reporting Database" separate to your "Primary data" database.

Once you start spreading your data across multiple databases and storing it in different structures managed by different apps with different APIs, suddenly getting to even eventual consistency can quickly become a non-trivial problem, which itself is usually solved or mitigated by adding more complexity.

Sometimes this complexity really is required because of incredibly large scale, large/numerous engineering teams working on one project, or unique business requirements - but my original point was that for most cases, particularly new products/projects that aren't going to have 10M+ daily users from launch, you should keep it simple until you know for a fact that it needs the complexity of a full CQRS + event sourcing system.

Re:CQRS: Command Query Responsibility Segregation (2011) by barumi on Wednesday November 11, 2020 @02:36PM (#25062010)
> Even though they're technically different concepts, I've found in practice they're almost always coupled together.

Not really. Event sourcing is typically implemented with CQRS, mainly due to how ES relies on streams of command messages and as CAP-related requirements already require mutable and immutable commands to be processed differently. However, CQRS has zero requirements other than segregating interfaces.

Hell, in languages like C++ you already get CQRS out-of the-box by following const-correctness.

Re:CQRS: Command Query Responsibility Segregation (2011) by unklefolk on Wednesday November 11, 2020 @11:48AM (#25059970)
One obvious drawback is the amount of boilerplate code and multiple files. Although the essence may be no more complex, the amount of "noise" and fragmentation across files can increase the mental load.
Re:CQRS: Command Query Responsibility Segregation (2011) by fulafel on Wednesday November 11, 2020 @03:34PM (#25062665)
Yep. Additionally to the separation you have the idea of domain specific commands instead of just writing objects/updating fields which lends itself well to custom side effect logic and constraints/sanity checks.
Re:CQRS: Command Query Responsibility Segregation (2011) by whalesalad on Wednesday November 11, 2020 @10:38AM (#25059210)
Well... you’ve just described the law of nothing in life is free. Of course there are trade offs with any architecture choice.
Re:CQRS: Command Query Responsibility Segregation (2011) by AndrewSChapman on Wednesday November 11, 2020 @10:52AM (#25059337)
Agree 100%. There are probably better alternatives if you're needing to improve scalability.