Why you need it
Most apps are quiet for hours: at night, at weekends, between bursts. An autoscaler that never goes below one copy still bills you for that copy all night while nobody visits. Going down to zero saves the money, but then someone has to wait for the first copy to start.
Think of it like this
A light on a motion sensor in a hallway. Nobody there, the light is off and costs nothing. The first person to walk in stands in the dark for a moment before it turns on.
Where you’ll find it
- AWS Lambda: Runs code only when a request comes, and offers provisioned concurrency to keep copies warm.
- Google Cloud Run: Scales to zero by default; a minimum number of instances keeps some warm.
- Knative: Brings scale to zero to any Kubernetes cluster.
What to know first
Autoscaling. A program changes the number of copies to match how busy they are. See Autoscaling.
Starting a copy. Finding a server, loading the code, starting the language, then running the app's own setup. Each step takes time.
How it works
- Zero copies when nobody comes. With no visitors, the platform stops every copy, and you pay nothing. This is the night with zero copies in the animation.
- The first visitor starts a copy. When a request arrives and no copy runs, one must start before it can answer. That wait is the cold start in the animation. Later visitors find it running: a warm start.
- Copies stay warm for a while. After answering, a copy is kept around for some minutes in case more visitors come. Only after a long quiet does it go back to zero.
- Make the start shorter. Smaller code, fewer libraries, and less work at startup all cut the wait. Some platforms can save a snapshot of a started copy and resume from it.
- Or keep one warm, and pay. Ask for at least one copy always running. Nobody waits, but the night costs money again, as at the end of the animation. Pick per app: a nightly report can wait 3 seconds; a checkout should not.
An example
A shop gets no visitors from midnight to 7:00. One always-on copy costs, say, 5 cents an hour: 35 cents a night for nothing.
With zero copies, the night costs 0. At 7:00 the first visitor waits 3 seconds for a cold start. Everyone after waits 0.2 seconds.
With one copy kept warm, the first visitor also waits 0.2 seconds, and the 35 cents is back.
Further reading
- Operating Lambda: performance optimization, part 1, AWS Compute Blog. What happens during a cold start, step by step, and what makes it longer. Start with this one.
- Lambda execution environment lifecycle, AWS Lambda docs. The life of one copy: start, answer, wait warm, stop.
- Minimum instances, Google Cloud Run docs. The keep-one-warm trade-off, from a second platform.