I am trying to understand the use cases for a child workflow with Temporal/Uber Cadence. What is the advantage of a child workflow vs. simply splitting your workflow into functions? I have a rather complex workflow that I am considering splitting into multiple child workflows, but I am unsure of the pros/cons of doing so.
- A child workflow can be hosted by a separate set of workers which don't contain the parent workflow code. So it would act as a separate service that can be invoked from multiple other workflows.
- A single workflow has a limited size. For example it cannot execute 100k activities. Child workflows can be used to partition the problem into smaller chunks. One parent with 1000 children each executing 1000 activities gives 1 million activities executed.
- A child workflow can be used to manage some resource using its ID to guarantee uniqueness. For example a workflow that manages host upgrades can have a child workflow per host (host name being a workflow ID) and use them to ensure that all operations on the host are serialized.
- A child workflow can be used to execute some periodic logic without blowing up the parent history size. Parent starts a child which executes periodic logic calling continue as new as many times as needed, then completes. From the parent point if view it is just a single child workflow invocation.
The main limitation of a child workflow versus collocating all the application logic in a single workflow is lack of the shared state. Parent and child can communicate only through asynchronous signals. But if there is a tight coupling between them it might be simpler to use a single workflow and just rely on a shared object state.
I personally recommend starting from a single workflow implementation if your problem has bounded size in terms of number of executed activities and processed signals. It is just simpler than multiple asynchronously communicating workflows.
Also it is frequently overseen that workflows are not just functions, you can use the full power of OO in them. Use structures, interfaces and other OO techniques to break the logic into more manageable abstractions.
© 2022 - 2024 — McMap. All rights reserved.