Hi all,
Can anyone help clarify about the responsibilities of a Process Manager to me in Event-Sourcing. I've trawled this forum, and online posts, but have found it hard to get good concrete examples of when not to use a process-manager, or what their responsibilities should not be.
My simplistic understanding is that they are used to orchestrating business processes that cross aggregates.
My main question is to what extent should they be involved in making a decision about that process, as opposed to just pure routing semantics?
It feels weird that all my process-managers are starting to require read-models which are themselves event-sourced from the domains I'm orchestrating, to be able to make decisions about the commands to issue to the domains. It feels like domain responsibilities are creeping into process-managers.
For a more concrete example -
1. Customer pays a scheduled payment of an order into an account using internet banking,
2. The internet-payment domain picks this up. Raises an event to say money has been added to an internet-payment account
3. This is subscribed to by a Process-Manager which is involved in orchestrating payments to the customer-accounts domain
a. There are some rules around how to distribute payments.
- If the payment matches the next due payment then issue a command to take it.
- If the payment matches the total due payment then issue a command to take it.
- If the payment matches the sum of next due payments of all that customers accounts then issue a command to pay them all.
- If the payment matches the total balance of all that customers accounts then issue a command to pay them all.
To be able to decide what to do, I've brain-stormed ways this Process Manager could work
1. Try the payment attempts in a preferred order (expressed by the business) one-by-one listening for success events, and trying the next on failure,
2. Consult a private read-model so it can make this decision pro-actively, even though it still needs to handle failure scenarios due to eventual-consistency issues
3. Fire a command which contains the preferred strategies straight to the customer-accounts domain
4. Move the concept of payments that occur via this particular channel into the customer-accounts domain, and expose a command which understands this decision making process.
5. Process Managers where the process is expected to very quickly complete are probably OTT and the customer-accounts domain should be able to listen to events and act accordingly
Solution 1 feels like it fits the idea of a process-manager, but also feels naive because it feels like nothing more than a proxy to a single domain.
Solution 2 feels like business logic has bled into what should have been simple orchestration, leading to additional complexity owing to the requirement to build loads of read-models (each process seems to get one).
Solution 3 feels like it buries the business process into a command which feels like an awkward place to put it
Solution 4 feels like it puts the behaviour in a more appropriate place, but could lead to a proliferation of unused commands if we ever wanted to change the process
Solution 5 feels like it loses the advantage of a process-manager and un-necessarily couples the customer-accounts domain to the epayments via these events.
I'd really appreciate any input on this,
Thanks,
Graeme