AWS Lambda - Cold Start Latency is now a past thing
Introducing Lambda SnapStart
2 min read
Anyone who has worked on AWS infrastructure knows how useful Lambda functions are for serverless computing. However, Lambda are also known for the pain of the huge latency in the cold start.
Whenever any web/desktop/mobile application starts, it goes through a series of steps for its initialisation. Similarly, for Lambda functions, initialisation step includes downloading the function’s code, starting the runtime, including all external dependencies, running the function’s initialisation code, including caches and other tasks.
All this leads to a good amount of latency in the initialisation phase of these Lambda Functions.
Solution - AWS Lambda SnapStart
On a very high level, SnapStart creates snapshots of a customer’s Lambda functions and then simply starts those up without having to go through the whole initialisation process in the subsequent restart calls.
A snapshot of the microVM is taken after the normal initialisation steps that can be used multiple times (also called cloned), to create multiple sandboxes that are initialised in the same way. Cloning like this has two benefits:
As the normal initialisation is not required more than once for each Lambda function execution. Thus, for a function with N concurrent executions the initialisation is completed in O(1) time instead of the O(N) time.
The cold start latency for applications that do a lot of work on startup (applications that use large language runtime or large frameworks and libraries) is significantly reduced.
According to the official documents, Lambda SnapStart can help to improve startup performance by up to 10x at no extra cost. It also keeps functions initialised and ready to respond in just double-digit milliseconds.
The underlying mechanism
Once the SnapStart is enabled, SnapStart performs a standard initialisation when you first run that function. After which, it creates an encrypted snapshot of the memory and disk state and cache that for reuse. Then, when the function is invoked again, Lambda will grab the cache and start up the function. Cached snapshots are removed after 14 days of inactivity.
How to use SnapStart
Users can activate Lambda SnapStart for new or existing Java-based Lambda functions running on Amazon Corretto 11 via the AWS Lambda API, AWS Management Console, AWS Command Line Interface and other AWS capabilities.
Click here for a detailed guide.
SnapStart ready AWS Regions
On the time of writing this article, SnapStart is available in the US East (Ohio, N. Virginia), US West (Oregon), Asia Pacific (Singapore, Sydney, Tokyo), and Europe (Frankfurt, Ireland, Stockholm) Regions.
References used in the article -