Comments (5)
@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.
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.
+1
from nest-cqrs-example.
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)
- Create new tiers
- UUID do not define a '.' subpath HOT 1
- client-side example HOT 1
- Opinion on how to plugin persistance
- Not sure if services are still relevant in cqrs HOT 1
- Add sample logic HOT 1
- DDD approach in Nest CQRS HOT 1
- Naming inconsistency
- Using Kafka as Event Bus HOT 6
- Another Aggregate Root
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nest-cqrs-example.