Giter VIP home page Giter VIP logo

Comments (5)

jcjpsa avatar jcjpsa commented on May 22, 2024 3

@johncmunson do you have a reference for a better example like this repo, other than the link you provided in your comment. I am interested in learning the correct pattern.

from nest-cqrs-example.

rrnazario avatar rrnazario commented on May 22, 2024 2

I believe, instead having the previous query handler signature, it should be better to have something like:

export class GetHeroesHandler implements IQueryHandler<GetHeroesQuery, GetHeroesResponse>

Where GetHeroesResponse configures another domain to be proper returned on handler.

from nest-cqrs-example.

brianpooe avatar brianpooe commented on May 22, 2024

+1

from nest-cqrs-example.

kommunicate avatar kommunicate commented on May 22, 2024

There seem to be 2 conceptual differences between this package and what is generally recognized as the CQRS pattern. Unfortunately these differences can't be changed in a non-backwards compatible way. In the current implementation, ICommand is completely separate and parallel to IEvent but it should probably extend IEvent instead (at least, I think this is the fastest and easiest way of addressing this issue). The other issue is that Sagas are implemented as projections; not sagas -- they should be listening to the event stream; not the command stream. Canonically, sagas are used to coordinate between multiple aggregate roots. Projections are derived constructs from events.

In DDD the difference between commands and events is the intent of the calling system. An event is a fact, a command is a request to change the state of the aggregate. In the code, the execute method for EventHandlers are correctly defined as pure functions. This means that aggregate state is therefore defined as chained calls to event handlers -- h(h(h({state}))). However, that's only true if commands don't also change aggregate root state. Replaying only the events will have the effect of recreating aggregate state; allowing you to deal with system updates gracefully. State changes therefore get split into 2 parts: the command (the intent -- CreateOrder) and the resulting factual event (OrderCreated). If you were to replay the CreateOrder command it would have the effect of creating a new corresponding OrderCreated event. However, if you only replay the event, the system will gracefully recover. The sample project is so trivial that it side-steps one of the most common issues facing CQRS and event streamed applications -- aggregate mutations are almost always a 2-step process.

I see a lot of code in this package to support management of the AggregateRoot (a lot of autocommit and replay code is there), but it can never work because of the command / event issue. Projections have a similar problem -- they should be created from the event stream; not the command side. That's not to say that listening to commands isn't useful, the current implementation is superb for decoupling validations and provide a convenient place to persist commands. However, the name is different to what is generally understood with this pattern.

from nest-cqrs-example.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.