Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Event Handler / Saga / Where to Write Documentation #64

Closed
jsonberry opened this issue Apr 5, 2019 · 4 comments
Closed

Event Handler / Saga / Where to Write Documentation #64

jsonberry opened this issue Apr 5, 2019 · 4 comments

Comments

@jsonberry
Copy link

jsonberry commented Apr 5, 2019

I'm submitting a...


[ ] Regression 
[ ] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

My main concern is understanding a good place where to do writes.

I'm enjoying setting up the CQRS module in my current project, but I ended up dropping event handlers because I couldn't justify a real good use for them.

From command handlers I am publishing events with the eventBus, then creating sagas for events and additional command handlers for those because I want to:

  • Keep complicated async business logic at the saga level
  • Consolidate writes to a unified location (command handlers)

I chose this approach so that I can onboard others into the project and if they have questions about where to do writes/reads/more complex async logic, I can direct them as such:

  • writes -> command handlers
  • reads -> query handlers
  • more complex async logic / event sourcing-> saga

Am I missing something real obvious about event handlers? I fully understand I can inject into them and I can handle write logic there, but is there something better about the pattern that I am not groking?

Thanks!

Edit

I realize after reading/watching more about CQRS that this is probably just me needing to understand the pattern better.

For most of my use cases, especially for single transactions that don't require communication with other aggregates, I see that an Event Handler is a good place to do work. Transitioning to a Saga seems to come into play when there are multiple transactions that need to occur, but even then at the end of the Saga I'm not sure what I would need to do in the Command Handler at the end of a Saga if I'm executing transactions inside of the Saga.

@jsonberry
Copy link
Author

As I've continued on in my ES/CQRS learning I've become more familiar with the patterns so where to do a write is not so elusive now.

It looks like people want to expand the official NestJS CQRS example, so maybe I can make some suggestions on that project while I'm continuing to learn.

Cheers 🍻

@subovietnam
Copy link

how using to rollback transaction in cqrs and event sourcing, in sagas when have event failed or message broker failed. Thanks all

@kodeine
Copy link

kodeine commented Jan 13, 2021

@jsonberry i'm in the same boat as you were a while ago, could you please confirm if i'm following the right pattern.

Account has many users.

User App: CreateUserCommand -> write to db, result goes to aggregate -> commit() -> UserCreatedEvent

Account App: Saga ofType UserCreatedEvent -> use the userId from event send new command -> CreateAccountCommand

i'm not using UserCreatedEventHandler here... should i be doing writes in there? so what needs to happen in command handler then...

@jsonberry
Copy link
Author

jsonberry commented Jan 13, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants