Idiomatic way of message passing to child workflows from external source

Hello, I have a user case where we have deep hierarchy of workflows, activities and child workflows and all workflow has to listen on a external message to stop its executing at any time in lifecycle.

for example:

parent_workflow_1 → activity_1, child_workflow1, child_workflow2
child_workflow1 → child_workflow1.1, child_workflow1.2
child_workflow2 → activity2.1, child_workflow2.1
child_workflow1.1 → child_workflow1.1.1

We have an API which external user calls which basically acts as a trigger point to cancel all workflows, including child workflows, basically everything which are processing and do not proceed further.

I have been thinking of 3 approaches:

  1. whenever the API call is being made, search the trace of workflow using search API and send updates/signals all child workflows to stop.

  2. have a workflow manager (which is a workflow) which manages all workflows. basically any workflow wants to spawn a child, it will ask the workflow manager to spawn that child. That way the workflow manager will keep track of all the workflows in the system and we only need to keep track of workflow manager id. whenever the external API call is being made, we send signal/update to only the workflow manager and workflow manager will handle the passing of signal/update to all the workflows that it has spawned.

  3. Have a tight coupling b/w each parent and child workflow meaning only parent can spawn its child and keep tracks of all child workflow it has spawned. we keep track of a single parent workflow id which is entry point to all other workflows and whenever there is an API call is made we only send signal/update to this parent workflow, which in turn sends signal/updates to its child workflows, which in turns sends signals/updates to its child workflows and eventually propagate to all child workflows like that.

keep in mind that we have to listen to this API signal/update all the time, coz it can happen at any stage of entire lifecycle of workflows.

  1. How to approach this problem in idiomatic way?
  2. can you provide some code example in Go on how to implement the solution?

This is actually what it means to have a “child” workflow: “A Child Workflow Execution is a Workflow Execution that is spawned from within another Workflow in the same Namespace.” (Child Workflows | Temporal Documentation)

If you set the child workflow’s Parent Close Policy to “Request Cancel”, the child workflow will automatically be sent a cancel request when the parent workflow closes.