I have a Lambda function about data science that gets a user id and a list of operations to perform over the data of this user.
Example path:
calculate?userId=1&operations=func1,func2,func3,func4,func5
In the Lambda function I am running calling all specified functions in a for loop and the functions are not that short-running. Every single one of them query the database and there are some overlapping queries. I have implemented sharing of the queries between functions.
I am suspecting that calling each function in the for loop is a good thing because for example while the func1 is running, func2 is waiting and so on. Should I:
- Run all of the functions in parallel with
asyncio? So that they do not wait for each other to finish. - Convert this function to a state machine and multiple Lambda functions (one for each function that I specified in query params) and implement necessary state transitions and etc.