Cold vs Warm start AWS Lambda
In AWS Lambda, Cold and Warm starts describe whether the platform needs to build a new execution environment from scratch or can reuse an existing one. This is especially relevant for Java/Spring Boot applications due to the time required to boot the JVM and application context.
Cold Start
A cold start occurs when a function is triggered but there is no idle “sandbox” (execution environment) ready to handle the request. This happens on the very first invocation, after code updates, or if the function has been idle long enough for AWS to reclaim the resources
The steps that are performed during a cold start are:
- Provisioning: AWS finds a space in its fleet and creates a new micro-VM.
- Downloading: Your container image or ZIP package is pulled from ECR or S3.
- Initialization (INIT Phase):
- Runtime Init: Starts the JVM.
- Function Init: For Spring Boot, this is when the ApplicationContext starts, beans are wired, and static code blocks run.
- Invocation: The handleRequest method finally executes the business logic.
For Java/Spring, this can add 5 to 10+ seconds of latency.
Warm start
A warm start occurs when a subsequent request arrives while an existing execution environment is still active and “frozen” in memory. AWS keeps these environments alive for a non-deterministic period to improve performance.
The Warm Start Process is simply “unfreezing” the environment and immediately calling the handler method. It skips the JVM startup, class loading, and Spring Boot initialization. Due to this th latency is usually reduced to double-digit milliseconds.