docs.nestjs.com icon indicating copy to clipboard operation
docs.nestjs.com copied to clipboard

Provide production level example

Open raymondsze opened this issue 5 years ago • 5 comments

It is not reasonable to use In-memory eventBus for doing cqrs in production. Instead, we should use some message broker system for eventBus like Kafka.

There are some questions in my mind.

  1. Although we could somehow switch the defaultPubSub to other mechanism like Kafka or something else, the underlying is using Rxjs observer pattern. What I currently do is switch the defaultPubSub to my customised PubSub. Run a kafka consumer in the defaultPubSub, and what I do inside is just subject$.next(event). To do so, I need to guarantee the event-handler have successfully response to the event then commit the offset, but how could I do that without changing the code in EventBus?

  2. I would like to implement a Saga Orchestrator pattern that to manage distributed transaction. But the saga is implemented by observer pattern as well. Again I need to guarantee the saga have successfully response to the event then commit the offset, how could I do that? I think Saga is just like a special kind of aggregate, which should have its own state as well. So saga is also just an event-handler that it could make use of commandBus to send command.

So, to summarise, is that using RxJs a correctly way to implement cqrs system? And I think really need some "production" level example that using nestjs/cqrs.

Thanks.

raymondsze avatar Jan 28 '20 12:01 raymondsze

@raymondsze Have you made any progress on this? I'm trying to swap in the eventstore node package for this as it interfaces with a lot of databases. I'm confused on how to ever change the default publisher. I see the method to set the publisher in the EventBus, but with how it's registered with nestjs, I'm not quite sure how to call it.

Stoom avatar Sep 13 '20 18:09 Stoom

Any updates on this?

kodeine avatar Dec 15 '20 15:12 kodeine

Have anyone managed to do something like this? I've found some libraries, but no reasonable example. I'm considering using NestJS in my new CQRS application, but this requirement (storing events in an event store) is mandatory.

Actually, not having this feature loses almost the entire purpose of event sourcing at all.

delucca avatar Feb 20 '21 15:02 delucca

Is this considered?

FBurner avatar Jun 10 '21 23:06 FBurner

Is there an update on this? How does saga compensation work in NestJS?

KieronWiltshire avatar May 19 '22 00:05 KieronWiltshire