Cold start

On this page 7

A cold start is the additional latency that occurs when a serverless platform must create a new execution environment for a function before it can process a request. The platform allocates an isolated sandbox, loads the runtime, downloads the code and runs the function’s initialization logic, and only then executes the handler. A request served by an environment that already exists is a warm start and skips all of these steps.

Cold starts are a direct consequence of the serverless model in the cloud: because the provider scales to zero and bills only for execution, idle environments are eventually reclaimed. The next request after a quiet period, and every request that arrives faster than existing environments can absorb, pays the initialization cost.

What happens during a cold start

A cold start consists of several phases, some controlled by the provider and some by the developer. The provider prepares the sandbox, typically a lightweight virtual machine or container, and attaches networking. The function package or container image is fetched, the language runtime starts, and the code outside the handler runs once. That last phase, the init phase, is where developer choices matter most.

The table below breaks a cold start into its phases and shows who controls each one.

PhaseWork performedControlled by
Sandbox creationIsolated microVM or container is allocatedProvider
Code downloadPackage or image layers are fetched and unpackedMostly provider, size by developer
Runtime startInterpreter or virtual machine bootsProvider, choice of runtime by developer
Initialization codeImports, SDK clients, configuration loadingDeveloper
First invocationHandler runs, lazy paths are compiled or loadedDeveloper
Phases of a cold start

After the request completes, the environment usually stays alive for a period the provider does not guarantee, often minutes rather than hours. Further requests reuse it, keeping database connections, caches and loaded libraries in memory. Each environment typically processes one request at a time in function as a service platforms such as AWS Lambda, so concurrency also drives cold starts.

Factors that determine cold start duration

Cold start latency ranges from well under 100 milliseconds for small functions in lightweight runtimes to several seconds for large packages with heavy frameworks. The exact figure depends on the provider, region and configuration, so published numbers should be treated as indicative, not fixed.

FactorEffect on cold startTypical lever
Runtime languageInterpreted and native runtimes start faster than JVM or .NET without tuningChoose runtime, use snapshots or native compilation
Package sizeLarger artifacts take longer to fetch and loadRemove unused dependencies, tree-shake bundles
Memory settingMore memory usually brings proportionally more CPURaise memory for CPU-bound initialization
Initialization logicEager loading of SDKs and configuration adds timeLazy-load rarely used modules
Network attachmentPrivate network setup once added notable delayUse current platform networking, avoid extra hops
Container imagesLarge images increase fetch timeUse slim base images and layer caching
Main factors and their influence

The memory setting deserves particular attention. On several platforms, CPU share scales with memory, so a function configured with the minimum memory may initialize several times more slowly than the same function with more memory, sometimes at a similar total cost because it finishes faster.

Cold start is often confused with other sources of slowness. Distinguishing them avoids optimizing the wrong layer.

EffectWhen it occursDistinguishing sign
Cold startNew execution environment is createdOnly some requests are slow, mostly after idle periods or bursts
Warm startExisting environment is reusedConsistently low overhead
ThrottlingConcurrency limit is reachedErrors or retries rather than slow success
Downstream latencyDatabase or API is slowSlowness persists on warm invocations
Container scale-upOrchestrator adds pods or tasksDelays of tens of seconds, not milliseconds
Cold start and neighboring latency sources

Monitoring tools usually report an init duration separately from the handler duration. Examining the percentage of invocations with a non-zero init duration, and the tail latency at the 99th percentile, shows whether cold starts actually affect users.

Techniques to reduce cold start impact

Mitigation either makes each cold start shorter or makes cold starts rarer. Provisioned concurrency, offered under various names by major providers, keeps a fixed number of environments initialized at all times, which removes cold starts up to that level but reintroduces an always-on cost. Snapshot-based features restore a pre-initialized memory image instead of running initialization again.

  • Keep deployment packages small and initialize only what every request needs.
  • Create SDK clients and connection pools outside the handler so warm invocations reuse them.
  • Use provisioned or minimum instances for latency-critical, steady traffic paths.
  • Prefer asynchronous designs with queues where users do not wait for the response.
  • Avoid scheduled warming pings as the main strategy, because they keep only one environment warm and do not cover bursts.

The following decision table helps match the technique to the workload.

WorkloadRecommended approachReason
Background processingAccept cold startsNo user waits for the result
Public API with steady trafficProvisioned concurrency for the baselinePredictable latency at known cost
Spiky interactive trafficSmall packages, fast runtime, snapshotsBursts always create new environments
Strict low-latency serviceContainers or always-on instancesServerless scaling cannot guarantee zero cold starts
Choosing a mitigation strategy

Common misconceptions about cold starts

A frequent mistake is assuming that cold starts happen only after long idle periods. In practice, any increase in concurrent requests creates new environments, so a sudden burst of traffic causes a wave of cold starts even on a busy function. Another misconception is that cold starts dominate latency for every application; for functions invoked thousands of times per minute, they may affect well under one percent of requests.

Finally, the environment lifetime is not a contract. Providers recycle environments for maintenance, updates and capacity balancing, so code must never rely on in-memory state surviving between invocations.

Explained without jargon

Think of a food truck that closes when there are no customers. When the first customer of the afternoon arrives, the cook has to start the grill, unpack the ingredients and heat the oil before making anything. That first order takes longer. Once everything is running, the next orders come out quickly.

A cold start is that first slow order. Serverless platforms switch off unused capacity to save money, and switching it back on takes a moment. The trade-off is simple: lower cost when idle, a short wait when activity resumes.

A typical use case

A retailer runs its checkout API as serverless functions written in Java. Most requests finish in about 80 milliseconds, but monitoring shows that a few percent of requests take more than two seconds, mostly in the morning when traffic ramps up. The init duration metric confirms that these slow requests are cold starts caused by framework loading.

The team removes unused libraries, moves rarely used clients into lazy initialization and raises memory from 512 MB to 1,024 MB. It also enables provisioned concurrency of 20 environments during business hours, matching the typical morning baseline. The 99th percentile latency drops below 400 milliseconds, and the extra cost is limited to the hours when customers actually shop.