Check out the latest Article
In this article I would like to explain batch processing using parallel shape in Logic App. Parallel Processing in Logic app is a mechanism by which two or more different actions can take place concurrently but independently.
Consider an example, We are going to create an Logic App API which accepts one parameter in URL and returns 5 records per call. The records will be selected based on the “Page Number” parameter that we pass in URL.
- If we pass 1, first 5 records of data will be returned.
- If the “Page Number is 2 then it would be second set of Records, that is 6-10 records.
Logic App gets those 5 records by calling the below REST API 5 times based on the “Page Number” parameter and returns the cumulative result.
GetPosts() Rest Service
The behavior of the REST Service is,
Since there is no ordering is important we could call the Services parallel using parallel shape. This cant be achieved using Logic App Designer and we need to tweak the code in code window. If we need to add any 2 shapes under parallel shape then we need to add previous shapes id into runafter() element.
In this example, I would like to add “Increment_PostNumberBy1” and “Increment_PostNumberBy1” shapes into Parallel shape, so I added the previous shape’s id “Intialize_variable” into runafter() that makes the designer as below.
We have one http GET receive shape that accepts one URL parameter called “pageNumber”, based on this page number we need to return the results
Assign the “pageNumber” in to a integer variable called “PostNumber”, use int() function to convert “pageNumber” into Integer and use mul() to multiply it with 5.
Create a parallel shape that has 5 branches and create the REST calls to the mentioned API to get respective posts.
Increment “PostNumber” by 1
Create a REST API Request using “PostNumber” variable.
Posts are in Latin language so we call Google’s translate API service to convert it in English
Accumulate the result and from a JSON response and return to the caller.
The overall workflow would be as follows,
In PostMan, the API call would be,
I have used PostMan for testing and Using parallel shape it took almost 5 seconds average to process it.
But if we change the workflow to Sequential, the average came down to 3 seconds
Our Sequential flow would look like below,