eventhorizon
eventhorizon copied to clipboard
[doc] Create an example of a Saga for multiple aggregates
Hi. I want to see an example of multiple aggregates in a project to see how they communicate. :)
Sounds like it could be a good example. Could you describe in more detail what you would like to highlight?
I want to see:
- How two aggregate roots can communicate together.
- How to use two aggregates in a domain service which require two aggregates to complete a command.
Basically you should never have a command that directly affects multiple aggregate roots. If you need that you should probably create a saga that issues one of the commands as a side effect to an event from the first command.
Relating to your question, a more complex saga example could be good to have. I'll try to add that at some point.
Tks, I will waiting for the example. May I contribute to that PR for learning?
You can propose an example if you want to learn about it.
Maybe a e-commerce checkout could be a good example:
- One simple domain called
Order
, with commands and events forCreate
,Fulfil
andReject
. - One simple domain called
Payment
, with a commandRequest
with eventsAccepted
andDenied
. - A saga that reacts on
Order.Created
and issues aPayment.Request
command. It will then fulfil or reject the order depending on if the payment was accepted or denied.
Idea is too have small aggregate. One aggregate does not have other aggregate instead it can have id of aggrgate. If u read akka actor model it says result of one aggrgate can be passed to other. Here one aggrgate result can be passed to other.
Shouldn't a saga be able to react on a bunch of events? Currently It's interface only relies on a single event only.
In that case the saga has to keep track of incoming events until it has collected all affected events. Then it can continue processing. A saga is meant to keep its own internal state if required.