post-thumb

Tips to Setup Serverless Architecture with Azure Functions or AWS Lambda.

Serverless architecture is a way to reduce your administration and maintenance work on infrastructure. You can put all your efforts into developing new features but not managing the backends like EC2, EKS, ECS on AWS or VM, Container Instance, and App Service on Azure.

One more advantage is saving server costs and human resources because the server can automatically scale up and down to zero instances on demand. You don’t have to think about how to set up and manage your network and infrastructure.

If you are working in a small team with less manpower to take care of backends, serverless architecture is a perfect solution for you.

However, there is a potential problem called Cold Start that you should be aware of when setting up serverless infrastructure like Azure Functions or AWS Lambda.


What is Cold Start?

Cold Start means your web application needs more time to serve the first request. Usually, this may take more than 10 seconds to allocate and start the server instances for your application.


What is its impact?

If you implement a business-critical API on Azure Functions like payment, the user will fail to complete the purchase due to a long waiting time in the response.

Why ?

Because by default setting the client’s Http lib or network device may disconnect the connection when the Http response is too long to be finished

What is worst, this occasional problem is hard to discover after your release your services. You may gradually lose your users by providing unreliable services without awareness.


Solution :

Fortunately, you can set up a [Premium plan](https://learn.microsoft.com/en- us/azure/azure-functions/functions-premium-plan?tabs=portal) when creating Azure Functions to eliminate the Cold Start problem.

[Premium plan](https://learn.microsoft.com/en-us/azure/azure- functions/functions-premium-plan?tabs=portal) allows you to set up the minimal instance to serve your web app. For example, you can set up one server instance to be always online to achieve high availability of your services.

In addition, though AWS Lambda has a cold start problem, AWS has provided provisioned concurrency to resolve this issue since late 2019.

Provisioned concurrency initializes a requested number of execution environments so that they are prepared to respond immediately to your function’s invocations.

Note that configuring provisioned concurrency incurs charges to your AWS account. reference

Remember to solve the cold start problem can bring a higher cost no matter if you use Azure Function or AWS Lambda. It’s better to set it up for the production environment.


Summary

By default, Azure Function is set up by Consumption Plan ( pay-as-you-go ), which can significantly save costs during the development phase.

For the Production environment, it’s recommended to set up the [Premium plan](https://learn.microsoft.com/en-us/azure/azure-functions/functions- premium-plan?tabs=portal) to completely eliminate the Cold Start problem and ensure the high reliability of your service in Azure Functions by preparing a warm execution environment for your function.

I hope this article can help you to set up a serverless architecture with high availability of Azure Functions.

If you found this article helpful, please follow us on Facebook to get the latest tutorials in the future.

Thank you for reading!