I have a use case where I need to execute a bulk API call with a list of items on a 3rd party API using Temporal workflow. The payload includes callback URLs to receive notifications on the completion of each item as they are processed. The 3P API accepts the request and returns immediately.
The bulk API can partially fail, so I need to retry the failed items up to a specified number of retries. If some items fail again in the first retry, I need to retry the remaining failed items until all items succeed or the retry limit is reached.
I understand that notification can be done through signals. However, I am not sure how to enable retries only for the failed items. I thought about using heartbeats, but I’m not sure if it’s possible to use the heartbeat at a workflow context level. Another solution is to keep a map of items sent to the 3rd party API in the main workflow and update their status on every signal. In case of failure, reinvoke the activity with the failed items to retry on the 3rd party API.
Could you provide guidance on how to achieve this in a Temporal workflow?
I thought about using heartbeats, but I’m not sure if it’s possible to use the heartbeat at a workflow context level.
Heartbeat is not meant for this, it is to inform the Temporal server that the activity is still running, and you are right, you can not use it from the workflow context.
Another solution is to keep a map of items sent to the 3rd party API in the main workflow and update their status on every signal. In case of failure, reinvoke the activity with the failed items to retry on the 3rd party API.
I was picturing something like this as I was reading the question. This will work.
One think it is not clear to me, do you send all the items at the same time or one by one?
Thanks @maxim for the reply.
The batch size is below 20 in all the cases i know of.
These are string inputs. Considering 100-200 bytes per input. The total size of the batch would be in the range of 2-4 KB. It may be less also but it wont exceed this size.