I have worked in a few of the applications where parallel execution is required to perform some computing tasks. The main advantage of this approach is that you get the desired output pretty quickly, depending on the sub-threads that you create. It could be achieved in multiple ways using different technologies. However, the challenge in these approaches is that, if something goes wrong in the middle of any of the sub-thread, it's not easy to self-heal and resume from where it was stopped. I'm sure many of you might have faced similar problems in your application, as it is a very common business case.
In this recipe, we will implement a simple way of executing a function in parallel with multiple instances using the Durable Functions for the following scenario.
Assume that we have five customers (whose IDs are 1, 2, 3, 4, and 5 respectively) who approached us to generate a huge number of barcodes (say around 50,000). It would take a lot of time to generate the barcodes as it would involve some image processing tasks. So, one simple way to quickly process the request is to use asynchronous programming by creating a thread for each of the customers and then executing the logic in parallel for each of them.
We will also simulate a simple use case to understand how the Durable Functions auto-heals when the VM on which they are hosted goes down or is restarted.