Should I use AWS Lambda SnapStart?

Mohamed Latfalla
AWS in Plain English
4 min readDec 20, 2022

--

One of the main issues that makes Lambda struggle in some scenarios is Cold Start. Which is the time that Lambda takes for the first execution.

Cold start is the first execution after a new version got published or an exection after a long inactive period of time, mainly.
This execution cause a delay in finishing the request, as it takes time for AWS to prepare the computing unit, which is relatevly fast, and to do the Init phase, which could take a long time mainly for Java becaues of the nature of code compiling.

Note: If you want to see your request from the moment it hits Lambda endpoint till the end, enable X-Ray. Its not free.

Let me add more into this point as it is the key point for this feature.
When your Lambda function set for a long period of time without executions, AWS will reclaim its space from the EC2s that are specified for Lambda. Also, if you published a new version of the same function, which it could be adding a single space into your code, will delete the current version from the EC2s and replace it with the new version. These two main point of causing the cold start.

Cool, So what SnapStart does?

SnapStart will cache the init phase internally for you. So when you call the function, it will pring the cached version to shorten the Init phase. In this case, the first execution will be way faster. As AWS shared, the cache part is free, yaay!!.

Lets dive into the Pros and Cons for this feature shall we?

Pros:

A- Speed: Lambda first execution would be much faster, especially with the heavy runtime like Java. Because the function resources initialization will be cached, Retrieving a cached image of your executable is much faster than rebuilding it every time you need to scale up or run it after inactive period.

Thats it! This feature is really to the point. It solve a big issue for many users.

I know its a new feature but lets adress the obvious points that AWS will need to deal with soon.

Cons:

A- Runtime: They support only Java for now. Which is obvious as the nature of code compliling and the number of different frameworks you can use. Other runtimes like Python is really fast to load in Lambda. Enabling this feature as well for Python makes it much powerfull and ready for more scenarios.

B- Caching: The solution cause another set of issues. Lambda is a computing unit that does what you code it to do. So, you must do a lot of testing for your code before you apply it on production workload. You much check your code for not using or relying on a set of files, saved configuration that gets pre-compiled because there is a chance that it would be using some cached values.

C- One function, multiple versions?: Because Lambda has a lot of ways to be triggered, you must update your trigger with the coorect ARN to use the version that has the SnapStart. If you don’t, it won’t use it and will use the normal function, with no SnapStart previlidge. But if this is the case, every new version, a new trigger update? hmmm no good.

I can add more points but lets focus on what is the takeaway from this feature.

It is really great feature. I’ve been using Lambda for the past 4+ years and I faced many time the cold start issue. But from my point of view, it could be better.

Like for example, add more runtimes. I know it could be a big challenge to release it with other runtimes like Python, which I can directly point to one potential issue, multiprocessing manager. Or the smartness in the trigger services to use always the SnapStart version. But these things will eventually come.

Should I use it?

If you are a Java user, I believe its a must for you to adopt this feature. It dissolve the aincient issue of Serverless. It would give you almost the same effect of running your function on an EC2, faster. But, you must do a lot of testing for your code. You built your function on a way that it works with and without Cold Start. This one might shake your code a bit.

More content at PlainEnglish.io. Sign up for our free weekly newsletter. Follow us on Twitter, LinkedIn, YouTube, and Discord.

Interested in scaling your software startup? Check out Circuit.

--

--

An indiviual who looks way far to the future. Tech is the core of my soul and football is what makes me alive.