# Cold start

> The extra wait when a serverless function has to boot before answering.

- Level: Intermediate
- Topics: Cloud
- URL: https://tidbit.legios.com.ar/cold-start/
- In Spanish: [Cold start](https://tidbit.legios.com.ar/es/cold-start/)

A **cold start** is the delay that happens when a request arrives and there is no ready copy of your code to handle it. In serverless platforms like AWS Lambda, nothing runs while nobody is calling. When a request comes in, the platform has to find a machine, create a small isolated environment, load your code and its libraries, and run your setup, all before it can start on the actual work.

Once that environment exists, the platform keeps it around for a while. Requests that land on it are **warm starts** and skip all that preparation. So the first request after a quiet period, or the extra requests during a sudden spike that need new copies, pay the cold start; the rest do not.

How long it takes varies a lot: from tens of milliseconds for a small function to several seconds for a big one with heavy libraries or a slow-starting runtime. For a nightly batch job it does not matter; for an API a person is waiting on, it can. Common fixes are smaller packages, doing less at startup, and paying to keep some copies always warm, which AWS calls **provisioned concurrency**.

## An analogy

Like a café that turns the espresso machine off when it is empty. The first customer of the morning waits for it to heat up; everyone after that gets their coffee right away.

## Keep in mind

- Happens when no ready copy of the code exists and one must be created.
- Warm starts reuse an existing environment and skip the setup.
- Ranges from milliseconds to seconds depending on code size and runtime.
- Smaller code and kept-warm capacity reduce it.

## Go deeper

- [Lambda execution environment lifecycle (AWS docs)](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtime-environment.html)
- [Cold start (computing) on Wikipedia](https://en.wikipedia.org/wiki/Cold_start_(computing))

## Related terms

- [Serverless](https://tidbit.legios.com.ar/serverless/): Code that runs only when called; you never see or manage the server.
- [AWS Lambda](https://tidbit.legios.com.ar/aws-lambda/): Run a piece of code only when something happens, with no server to manage.
- [Batch processing](https://tidbit.legios.com.ar/batch-processing/): Collecting data for a while and then processing it all in one big run.
- [API](https://tidbit.legios.com.ar/api/): The menu of things one program lets another program ask for.
