Durable Function App - Game changer
Sometimes we feel what could be the real use case for some of the latest technology advances coming every now and then and we don't completely follow unless we see the need in our project - well, this is an opportunity to understand, learn and implement.
One such requirement came on its way in our project and that's the durable function app. we have many third-party integrations out of which some are having real-time syncing options while others are not fully automated. the one which is not fully automated, we have dedicated hardware (not physical but the virtual machines) to pull the data on the frequency and process it.
As-Is Scenario: We had a small utility (a desktop app) that pulls the data from one system and processes that individually. It gets more than 20,000 records and to process each one takes around 1 second (approx.) on average it completes this job in 20,000 seconds. Not only that, post-process - someone needs to keenly check the database for an error and process those one more time.
Time to implement Azure Function: As a Cloud development team, we always look for an opportunity to move everything into the cloud, and more we see such flavors like above we jump on our chair. Happens right? :) That was the task and we started with a well-known serverless architecture. We have used the Azure Function App (version 1, I think that time).
Time to test but early to celebrate: Well, All done. The team has done all the coding and tested with a few (may be 10-15-20-50) records and every scenario was all covered. We ordered the pizza and about to celebrate the victory and guess what... we gave full load (a very 1st full trial - 20,000) records and It falls flat. The previous system was working at least (after taking the considered amount of time) but this one - stopped completely.
Back to Square one: Well instead of celebrating the pizza party, we back to the square one. We were thinking we missed some key aspects to consider and that's the timeout associated with each consumption plan. We started thinking of an alternative and studying things. We absolutely don't want to go for the Web App, Job, Batch process. (kind of stubborn attitude to know more from the problem rather than going with an alternative)
Found the Solution: A year and a half back, Microsoft has introduced the durable function app and it's not just a function app but rather its orchestration. It allows the process to work in an asynchronous fashion, it can have more sub-contractor orchestration and actionable activities. Finally, We have used the Function Chain, Fan-In and Fan-Out, Retry Fun Activity - some of these important architecture patterns. This not only solves the issue but also reduces the time from 5-6 hours to just 12-15 minutes.
The icing on the cake: We thought let's solve the other problem. The problem was an engineer spends his valuable time to do the analysis post activity and understand what went wrong. We found we can do a much better job there. we have used the logic app where it read an email, save the file in blob storage and kick up the durable function app and during the process, it generates enough logs (status and other information). On completion, It sends the email to the engineer and marks that email as read. The engineer just needs to filter on the status and worried about just those records which fail.
Celebration time: Finally! It's really a time to celebrate. We have used the following technology stacks, tools, and architecture/ design patterns.
- Azure Durable Function App (FanIn, FanOut design pattern, Function Chain design pattern, Timeout and Retry design pattern, Sub Orchestration)
- Azure Logic App
- Azure Office 365 Email Client
- Azure Blob Storage
- Application Insights
- Core Logger
- CSV Parser
- Postman