This is my first time using temporal. I would like to ask what best practices exist for my case study.
I’m writing an application that when a new user is added, needs to contact a third party service and get the IDs of all the user’s products. There could be thousands of them. Then for each product, another query needs to be done to get its characteristics. But these queries need to be done in parallel.
I have calculated the structure, it turns out that I will have
FetchUserWorkflow, FetchProductsWorkflow, FetchPropertiesWorkflow. Each workflow will have one activity with retrieve (to query the api) and store (to save to the database) methods. I say this to make it clear that it is the child workflows that are needed, not just the activities.
FetchUserWorkflow will be the parent for the other two. Pseudocode:
FetchUserWorkflow:
$productIds = await executeChildWorkflow(FetchProductsWorkflow)foreach($productIds as $productId):
$promises = executeChildWorkflow(FetchPropertiesWorkflow)$result = await Promise.all($promises)
As far as I understand, this code will send tens of thousands of tasks to temporal at once, but they will be executed according to the number of workers set in the configuration. Is this a normal practice?
The issue is that a user may have many items - thousands, tens of thousands, maybe even hundreds. In any case, I don’t want to be limited by the resources of the process in which the workflow is executed. And getting the result from a bunch of workflows into a variable will prove to be too resource-intensive, the only issue is their number, which I can’t control.
In this regard, I would like to know what tactics would be correct in the case when I need to process thousands of tasks in parallel and wait for completion in the parent workflow.