Search code examples
.netasp.net-coredesign-patternscqrs

CQRS with event driven architecture but without event sourcing


Before posting this, I referred many sites and learning platforms but saw similar pattern of developing CQRS with event sourcing. Again to have proper events you need to follow DDD pattern. I have below questions.

  1. Can we keep read and write DB in sync just by publishing event from write model and consume it at read model using event handler and updating read database
  2. Why Event-Sourcing and replay of events needed if my requirement is to only see latest data
  3. I can manage audit of data as and when events reaches at event handler
  4. I can version messages based on timestamp in case if race condition.
  5. Please explain by doing steps 1,3 and 4, am I still following CQRS pattern?

FYI, I am using .NetCore 3.1, AWS Lambda services, MassTransit as a MessageBus and SQS as a transport.

Thanks in advance.


Solution

  • Can we keep read and write DB in sync just by publishing event from write model and consume it at read model using event handler and updating read database

    Sort of; there are some trade offs. On the "happy path", it just takes a bit longer, because you have to wait for both writes to finish. When something goes wrong writing to the second database, it gets messy, because your two databases are no longer synchronized and you have to decide what, if anything you are going to do to recover.

    If your reads and writes are to the same database, then that second problem goes away if you update them in the same transaction.

    Why Event-Sourcing and replay of events needed if my requirement is to only see latest data

    You don't. If you don't need the ability to reconstruct what your information looked like in the past, then you don't need event sourcing.

    (You might think of it like source code - if you only ever need the latest version of your sources, then that simplifies the requirements for your "source control system".)

    Please explain by doing steps 1,3 and 4, am I still following CQRS pattern?

    Sure. "CQRS is simply the creation of two objects where there was previously only one." -- Greg Young, 2010. You may not be enjoying "all" of the advantages of CQRS (because you've made different trade offs).

    The important thing is to be aware that you are making tradeoffs, and what the implications are.