One possibility is that perhaps every “MoneyTransferred” event would result in a new “Grant Bonus” workflow being launched to handle that particular event. However, you say that “the” Grant Bonus workflow would subscribe to the “MoneyTransferred” event, which to my mind raises the question of how the Grant Bonus workflow would be identified… is there a single Grant Bonus workflow running which receives every “MoneyTransferred” event, or, if there are multiple Grant Bonus workflows running continuously, how would you identity which Grant Bonus workflow should receive a particular “MoneyTransferred” event?
(For a design where there was a single Grant Bonus workflow that would be signaled for every “MoneyTransferred” event, you’d run into the issue that while Temporal supports millions of concurrently running workflows, any single workflow instance can only support processing a limited number of workflow events per second).
I suspect that it would be simpler to have a new “Grant Bonus” workflow launched for each “MoneyTransferred” event. The workflow instance would naturally represent and implement the process of granting bonuses for that particular event, and the workflow instance would be finished when the bonuses had been granted.
Another question is, would it be enough to decouple the code, or do you really need to decouple the workflow?
For the former, imagine that in your code base you had a “Transfer Money” module and a “Grant Bonus” module. The “Transfer Money” module, in the code, would generate a “Money Transferred” event; the “Grant Bonus” module would, in the code, register that it wanted to receive “Money Transferred” events, and, on receiving such an event, start the “Grant Bonus” workflow. The whole thing would run in the “Money Transfer” workflow; you’d have a separation of concerns in the code while in execution the “Money Transfer” workflow would end up launching the “Grant Bonus” workflow.
Perhaps you might want to really decouple the workflow execution; then you might have the “Transfer Money” workflow launch a “Money Transferred” workflow, which in turn would launch registered workflows such as the “Grant Bonus” workflow.
And perhaps you might want to dynamically change how events are responded to; in which case the information of how to respond to an event (such as which subscriptions it had) would need to be stored somewhere… either in a workflow or an external database. The problem with storing dynamic subscription information in a workflow instance is again the issue that you’d want to avoid having a singleton workflow in the system that would become a bottleneck. So I expect you’d likely end up wanting to store dynamic subscription information an external database. The implementation then becomes a workflow generates an event by calling an activity; the activity reads the subscription information from the database and then launches such workflows as are required by using the Temporal client.