How to Avoid AWS Lambda Cold Starts?

in cloud •  3 years ago 

image.png

Say your company is facing major database corruption and you moved to cloud services like AWS for reliability, fault-tolerance, and scalability. Eventually, you switched to Serverless architecture, and AWS Lambda became a core part of its ecosystem with many critical functions being handled by it.

Now, just when you thought you’ve solved a problem, you experience a cold start that created a startup latency. It’s a common problem associated with AWS Lambda that takes initial setup time in serverless app development, slowing the Lambda function and disrupting the user experience. This blog discusses how you can prevent this scenario and solutions based on experiments carried out by serverless experts.

Reasons for AWS Lambda Cold Starts

A cold start is a common occurrence when a function is called for the first time after deployment as its container takes time to form. Ergo, this causes a few seconds delay, hampering an application’s productivity. In other cases, programming languages with higher latencies and a number of dependencies associated with Lambda functions affect cold starts. For instance, when you call a function, all its dependencies are imported into the container for Lambda functions which further adds to latency.

Ways to Reduce AWS Lambda Cold Start

  1. Avoid HTTP/HTTPS Calls Inside Lambda
  2. Preload All Dependencies
  3. Avoid Colossal Functions
  4. Reducing Setup Variables

Experimentation-based Techniques to Prevent Cold Start

  1. Run Lambdas Out of VPC
  2. Provisional Concurrency
  3. Keeping Your Lambda Functions Warm
  4. Choosing Right Programming Language
  5. Continuous Monitoring Using Log Data
  6. Reducing Function Dependencies
  7. Optimize Memory and Code Size
  8. Load Less Resources
  9. Deployment Artifact Size Matters

Check out the original article to read more about how to avoid AWS lambda cold starts.

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!