Jan 27, 2022. 12 min
How to Prevent Cold Starts in AWS Lambda
Rise of Serverless
Serverless computing, also known as function as a service (FaaS) allows developers to run code without having to worry about installing / managing the underlying server infrastructure. In spite of being relatively new (AWS Lambda was released in 2014), it has seen rapid adoption and the global serverless market is projected to go above $36 B by 2028. The benefits of going serverless are many:
- Developers can devote all their focus on developing the business logic and not the underlying operational overhead
- Pay as you go billing model can potentially cut costs, especially if the application has large amounts of idle time
- Scales automatically without having to change any configuration
However, there are some caveats one has to keep in mind to ensure that the applications are at its best performance, most important one being “cold starts”.
What are Cold Starts?
An application running on an EC2 server is always available to serve customer requests. However, an AWS Lambda function runs inside an execution environment which is spun up when a request is received. Unless the environment is already up, it may take a while for AWS to spin up a new container. This initial overhead is called a “Cold Start”. The actual duration of a cold start can vary based on the execution environment / other configuration values. AWS keeps lambda execution instances alive for 5 minutes after the request is received. If your application has significant idle time, the time spent on cold starts can add up and the average latency can turn out to be much higher than expected.
How to prevent Cold Starts in AWS Lambda?
AWS provides a mechanism called Provisioned Concurrency which allows you to choose the number of lambda execution environments to be kept alive all the time. AWS also allows you to automatically scale / schedule provisioned concurrency. While this is a good way to ensure that your average application latency remains fairly constant, it can add to your costs significantly since the billing includes both length of time Provisioned Concurrency is enabled and lambda invocations. Refer to AWS pricing for Lambda Provisioned Concurrency for more details.
Introducing Lambda Keep-alive
CloudAEye offers a “Lambda Keep-alive” feature with its suite of AI based operations management for applications. Based on your usage patterns, the lambda keep-alive solution intelligently estimates the number of expected lambda requests in every 5-minute interval and automatically keeps those instances “alive” so that your customers experience the lowest possible latency, at a fraction of the cost of Provisioned Concurrency.
Curious about AIOps?
Did you know that CloudAEye offers the most advanced AIOps solution for AWS Lambda? Request a free demo today!
Shashank works as a Pricipal Engineer at CloudAEye. He has over 10 years of experience with companies such as Oracle and GE. Shashank graduated from top tier colleges in India. He completed post graduate programme in Management from the Indian Institute of Management (IIM) Indore, rated top 6 among Indian B-Schools. He completed his Bachelor of Engineering from the National Institute of Technology, Karnataka - ranked among the top 10 engineering colleges in India.