CQRS without Event Sourcing - what are the drawbac

2019-03-09 00:25发布

问题:

Besides missing some of the benefits of Event Sourcing, are there any other drawbacks to adapting an existing architecture to CQRS without the Event Sourcing piece?

I'm working on large application and the developers should be able to handle separating the existing architecture into Commands and Queries over the next few months, but asking them to also add in the Event Sourcing at this stage would be a HUGE problem from a resourcing perspective. Am I committing sacrilege by not including Event Sourcing?

回答1:

Event Sourcing is optional and in most cases complicates things more than it helps if introduced too early. Especially when transitioning from a legacy architecture and even more when the team has no experience with CQRS.

Most of the advantages being attributed to ES can be obtained by storing your events in a simple Event Log. You don't have to drop your state-based persistence, (but in the long run you probably will, because at some point it will become the logical next step).

My recommendation: Simplicity is the key. Do one step at a time, especially when introducing such a dramatic paradigm shift. Start with simple CQRS, then introduce an Event Log when you (and your team) have become used to the new concepts. Then, if at all required, change your persistence to Event Sourcing and fire the DBA ;-)



回答2:

I completely agree with Dennis, ES is no precondition for CQRS, in fact CQRS on its own is pretty easy to implement and has the potential to really simplify your design.

You can find a smooth introduction to it here

Secondly what benefits does CQRS on its own bring to the table ?

  • Simplifies your domain objects, by sucking out all the query concerns
  • Makes code scale able, your queries are separated and can be tuned easily
  • As you iterate over your product design you can add/remove/change individual commands/queries, instead of dealing with larger structures as a whole (e.g. entities, aggregates, modules).
  • Commands and queries produce a well known vocabulary to talk with domain experts. Other architectural patterns (e.g. pipes and filters, actors) use terms and concepts that may be harder to grasp by non-programmers.
  • Limits the use of ORM (if you use one), I feel ORM's bring in unwarranted complexity if you try and use them for querying, the abstractions are leaky and heavy, trying to tune them is a night mare :) Using a ORM only on the command side makes things much easier, plain old SQL is the best for queries, probably using a simple library to convert result sets into DTO's is the most you need.

More on how CQRS benefits design can be found here

Also do not forget about the non tangible benefits of CQRS

If you still have your doubts, you may want to read this

We currently use CQRS for projects with medium complexity and have found it be very suitable. We started out using a custom bootstrap code and have now moved on to using the Axon Framework to give us some of the infrastructure components

Feel free to PM me in case you want to know anything more specific.



回答3:

There is a fundamental problem of Event Sourcing pattern, that is the events in the Event Store may not be compatible with your event handlers in your application any more due to code change.

That being said, whenever you modify the event handler by adding new features, you need to think about the backward compatibility. You have to make sure your code can always handle the same event in different stage created by different version of your code.

When your application becomes more complex, you will find it really pain in the ass to make it backward compatible.



回答4:

I think Event Sourcing is what makes people to be afraid of CQRS. And thats for a reason. Its not natural - when you interact with something in real world you don't need to get whole history about this object.

event sourcing is a completely orthogonal concept to CQRS” (source) - technically if you don't use ES you loose nothing from CQRS features.

I have no idea why Event Sourcing is considered as the only foundation for solving of some "messaging" related problems like: duplication/missing of messages, reordering of messages and data collisions, etc. Its not true that if you don't use Event Sourcing you cant create encapsulated means to solve such problems other way.

How i see alternative ways to implement CQRS's messaging using another data-organizing principle you can read here.

I propose "signed documents" approach where you treat your data not as composition of modification events, but as composition of immutable parts signed by responsible users. Im sure there can be a lot of other solutions to implement message flow and data storage. And you need to take your business model into account when selecting which one you like to use.



回答5:

In my opinion, you're making a big mistake by not using event sourcing with CQRS.

First up, you'll almost certainly have issues synchronising your Query model with the Command model. With an event store, if the query side ever gets out of synch, you simply need to replay your events to correct it. That's the theory anyway!

But with Event Sourcing, you also get to store the complete history of all entity transactions. And this means you can decide to create new queries and views after implementation. These are very often views that would not be possible with non-Event Sourced CQRS. I've heard Greg Young give the example of querying items that have been added, and then removed, from a shopping cart. With Event Sourcing this is possible. Without ES it's not possible because you only store the final state of the cart.