avatarVikas Taank

Summary

This context discusses AWS Lambda functions, focusing on layering, cold and hot functions, managing cold start latency, and the difference between reserved and provisioned concurrency.

Abstract

AWS Lambda Layers allow for easy management and sharing of common components across multiple Lambda functions. The context explains the concepts of cold and hot Lambda functions, with cold functions referring to a state where no dedicated infrastructure is allocated, and hot functions having instances already running and ready to handle additional invocations. Cold start latency is a significant consideration in serverless architectures, and the context provides strategies to manage or mitigate it, such as keeping functions warm, optimizing function code and dependencies, using provisioned concurrency, and optimizing runtime choice. The difference between reserved and provisioned concurrency is also discussed, with reserved concurrency allocating a certain number of function execution instances exclusively for a specific function, and provisioned concurrency allowing for the allocation of a specified number of execution environments for a Lambda function in advance to eliminate cold starts.

Bullet points

  • AWS Lambda Layers allow for easy management and sharing of common components across multiple Lambda functions.
  • Cold Lambda functions refer to a state where no dedicated infrastructure is allocated, and hot functions have instances already running and ready to handle additional invocations.
  • Cold start latency is a significant consideration in serverless architectures.
  • Strategies to manage or mitigate cold start latency include keeping functions warm, optimizing function code and dependencies, using provisioned concurrency, and optimizing runtime choice.
  • Reserved concurrency allocates a certain number of function execution instances exclusively for a specific function.
  • Provisioned concurrency allows for the allocation of a specified number of execution environments for a Lambda function in advance to eliminate cold starts.

AWS Lambdas Interview Questions

What is layering in the context of AWS lambdas?

Lambda Layers in AWS Lambda is a feature that allows us to easily manage and share common components across multiple Lambda functions.

A Layer is essentially an archive containing additional code, such as libraries, dependencies, or even custom runtime environments, that can be used by your Lambda function.

Layers can be included in your Lambda function’s deployment package without needing to include them directly in your function’s deployment package.

What is hot and cold lambda?

Answer:

Cold Lambda Functions

A “cold” Lambda function refers to a state where the function has not been invoked recently. In this scenario, no dedicated infrastructure is currently allocated for the function.

When a cold function is invoked, AWS Lambda has to initiate a new instance of the function. This process involves loading the function code and its dependencies, setting up the runtime environment, and then executing the function.

This startup process adds latency to the invocation, known as “cold start” latency.

Cold starts occur:

  • When a function is invoked for the first time or after being updated.
  • When scaling up, i.e., when the number of concurrent executions increases and additional instances are initiated to handle the load.
  • Periodically, if a function has not been invoked for a prolonged period, as AWS may reclaim the infrastructure for other uses.

Hot Lambda Functions

A “hot” Lambda function, in contrast, refers to a state where the function’s instance(s) is already running, having been recently invoked.

AWS Lambda keeps the instance warm, meaning it’s ready to handle additional invocations without the need for initialization.

Subsequent requests to a hot function can be processed with lower latency since the cold start overhead is bypassed.

How to manage Cold Start Latency for AWS Lambdas?

Cold start latency is a key consideration in serverless architectures, especially for applications where response time is critical. Here are some strategies to manage or mitigate cold starts:

  • Keep Functions Warm: Periodically invoke your Lambda functions (e.g., using Amazon CloudWatch Events) to keep them warm. This approach can help ensure that there’s always a warm instance ready to handle requests, although it may incur additional costs.
  • Optimize Function Code and Dependencies: Reduce the size of the function package and minimize dependencies to speed up the initialization process.
  • Use Provisioned Concurrency: AWS Lambda allows you to configure provisioned concurrency, which keeps a specified number of instances warm and ready to serve requests at all times.
  • Optimize Runtime Choice: Some runtime environments have faster cold start times than others. Testing different runtimes and choosing one that offers better performance for your specific use case can reduce cold start latency.

What is the difference between reserved and provisioned concurrency.

Reserved Concurrency

  • Definition: Reserved Concurrency is a setting that allocates a certain number of AWS Lambda function execution instances (or concurrent executions) exclusively for a specific function. This reservation ensures that the function has the necessary concurrency available when needed, up to the specified limit.
  • Purpose: Its primary goal is to guarantee a specific level of concurrency for critical functions, ensuring they have enough capacity to handle incoming requests. It also serves as a way to limit a function’s maximum concurrency to prevent it from consuming too many resources, which could impact other functions within the same AWS account.
  • Impact on Scaling: By reserving concurrency for a function, you’re essentially capping its maximum number of concurrent executions. While this ensures availability of resources for critical functions, it also means that the function cannot scale beyond the reserved limit.
  • Cold Start Influence: Reserved Concurrency doesn’t directly address or reduce cold starts. Functions with reserved concurrency can still experience cold starts when they scale from zero or when additional instances are initialized to handle more concurrency.

Provisioned Concurrency

  • Definition: Provisioned Concurrency is a feature that allows you to allocate a specified number of execution environments for a Lambda function in advance. These environments are initialized and kept warm, ready to execute the function with minimal latency.
  • Purpose: The main objective of Provisioned Concurrency is to eliminate cold starts for Lambda functions by ensuring that a specified number of execution environments are always ready to handle requests. This is particularly useful for applications requiring consistent, low-latency responses.
  • Impact on Scaling: Functions with Provisioned Concurrency can immediately respond to traffic spikes without latency penalties, as long as the traffic does not exceed the provisioned amount. If traffic exceeds the provisioned concurrency, the function can still scale by initiating cold starts for additional requests.
  • Cold Start Influence: Provisioned Concurrency effectively eliminates cold starts for the number of executions specified, offering predictable performance.
  • However, it requires careful management and planning to align with traffic patterns, as it incurs costs for the provisioned execution environments, whether they are used or not.

Lets understand this better , lets say we have to API running in serverless mode one is getUsers() and getUserProfiles(). Now Reserved concurrency means that AWS is allocating a maximum number of environments for that get/user/123 call to run and not exceed that limit so that other API can also execute with in that AWS account and not run out of resources.

However Provisioned concurrency solves the problem for Cold start latency and the AWS Lambda will upfront keep the certain number of instances warmed up in order to eliminate Cold start that is called Provisioned Concurrency. It does not have any account level interference with other Lambda invocations.

I have tried to explain this in the below illustration.

Thanks for reading and clapping. Please feel free to share and consider supporting me if you like my content.

AWS
AWS Lambda
Lambda
Concurrency
Cloud Computing
Recommended from ReadMedium