Workflow function with loops and long sleeps within each iteration

Hi,

I have a requirement to implement a long-running workflow function that needs to loop through an array of objects and potentially long waits between each iteration; what is the best practice to memorialize the loop’s current index and the input array such that when the workflow can survive server reboots, version upgrades, etc and resume at the correct index of the array?

1 Like

All workflow variables, including the loop index, are automatically durably memorized. So just a normal loop should work fine. The workflow ability to survive “server reboots, version upgrades, etc” is the main value proposition of Temporal.

1 Like

Thank you very much for your swift response! I had previously evaluated Temporal (with SDK 1.2) but due to other priorities, I had only recently been able to resume the evaluation. I was very impressed at the time with how Temporal simplified the work needed to implement fault-tolerant micro-service orchestration and am now even more impressed to see the prolific community here as well as the tremendous progress that has been made over the years. I look forward to working and incorporating Temporal into my project!

I would love to understand more under the hood about how Temporal achieved memorizing local private variables; would you kindly point me to the areas of source code so I can get a better understanding? I have used Apache Flink stateful functions and they required internal states to be defined via specific APIs (not dissimilar to how Temporal offers Workflow.sleep in place of Thread.sleep for example) in order to achieve this; I am simply curious and would like to learn more how this can be done without additional APIs.

Thank you again for your help!!

See the Fault Tolerant Distributed Microservices Orchestration with Temporal presentation. The animation that explains the recovery starts at 35:30.

I understand now, the internal state is durable (eg local variables) via playback mechanism, they are not persisted per se. Thank you again Maxim!

1 Like