CMD Guide
HomeSystem DesignScalable Systems (Advanced Topics)

What are Cold Starts and Warm Starts, and Why Do They Matter for Performance

A cold start is the latency you pay when the platform has no ready-to-run execution environment for your code, so before your handler can run it must create one: download the deployment artifact, boot a lightweight virtual machine, start the language runtime, and execute the initialization code that lives outside your handler. A warm start reuses an environment that already did all of that, so only the handler runs. Everything interesting about cold starts is about that one-time setup path — where the milliseconds go, and how to make the platform skip or pre-pay for them.

The idea generalizes (a cold browser cache, an app launched after reboot, an empty CPU pipeline), but those are all the same shape: first use pays for state that later uses inherit for free. The place it actually bites a systems engineer today is serverless — AWS Lambda, Google Cloud Functions, Azure Functions — because there the environment is created and destroyed by the platform on your behalf, and a cold start sits directly in the user's request path. So we trace Lambda concretely.

The Lambda execution lifecycle: INIT vs INVOKE

Lambda splits every environment's life into three phases: Init, Invoke, and Shutdown. A cold start is an Invoke that had to be preceded by a full Init because no environment existed. A warm start is an Invoke that landed on an environment still alive from a previous request.

Because Init is amortized across every subsequent Invoke on that environment, the whole cold-start problem reduces to: how long is Init, and how often are you forced to pay it? You are forced to pay it on the first request, on every scale-up to a new concurrent environment, and after each idle reap.

diagram
diagram

Worked trace: one Java Lambda, cold then warm

The numbers below are representative of a small Spring-based Java 21 function behind API Gateway. Exact values vary by memory setting (more memory = more vCPU = faster init), dependency weight, and region, but the proportions are what matter: the platform-owned steps are cheap and roughly fixed; your own init code is the elephant.

PhaseWhat happensColdWarm
Download codeFetch artifact to the worker (often cached in a shared layer)~80 msskipped
microVM bootFirecracker starts a fresh microVM (~125 ms, ~150/s per host)~125 msskipped
Runtime initJVM starts, JIT cold, classes loaded~400 msskipped
Init code (outside handler)Spring context, dependency injection, JDBC pool, AWS SDK clients, config load~2500 msskipped
HandlerYour actual business logic~40 ms~40 ms
Total≈ 3.2 s≈ 40 ms

The lesson: cutting cold starts is almost never about the platform's 200 ms of boot — it is about your ~2.5 s of framework/DI/connection setup. A Python function with a couple of light imports typically inits in ~150-400 ms total (microVM + CPython + import boto3); the same function that eagerly imports pandas or opens a warmed connection pool can jump to 1-3 s. Node is usually ~200-500 ms. Language choice matters, but what you do at import time matters more.

The old VPC tax (now mostly gone). Before September 2019, a function attached to a VPC created an Elastic Network Interface per environment on cold start, adding 10+ seconds. AWS re-architected this with Hyperplane (shared, pre-created ENIs via VPC-to-VPC NAT), dropping it to sub-second. If you read older material warning that "VPC = huge cold starts," that specific problem is fixed — but a cold start still pays first-connection DNS resolution and TCP/TLS handshakes to your database, which is real and lands in your init code above.

Mitigation mechanics: how each fix actually works

Provisioned Concurrency (PC). You declare N; Lambda runs Init on N environments ahead of time and keeps them warm and ready. Requests up to N never see a cold start — Init already happened. You pay a flat per-GB-hour rate for those N environments for as long as PC is enabled, whether or not they serve traffic. Spillover beyond N falls back to on-demand and can still cold-start. You can autoscale PC on a schedule or utilization target via Application Auto Scaling.

SnapStart. When you publish a version, Lambda runs Init once, takes an encrypted memory + disk snapshot of the initialized Firecracker microVM, and caches it. On a cold start it restores from the snapshot instead of re-running Init, using lazy (copy-on-write, on-demand page) loading so restore is fast — typically pulling cold starts from seconds to a few hundred milliseconds. For Java it hooks into CRaC (Coordinated Restore at Checkpoint) so you can register beforeCheckpoint/afterRestore callbacks. SnapStart is free for Java; for Python and .NET there are charges for snapshot caching and restore. Crucially it does not require paying for idle capacity — the snapshot is the cost.

Keep-warm pings. A scheduled event (e.g. EventBridge every 5 min) invokes the function to prevent reaping. It keeps roughly one environment alive, does nothing for concurrent cold starts under load, and burns invocations. It is a stopgap, not a scaling strategy.

Pitfalls

When to use each — and when NOT to

The decision is a spend-vs-latency trade against your traffic shape and runtime.

Crisp rule: spiky/tolerant → on-demand; latency-critical predictable baseline → Provisioned Concurrency; heavy Java/Python init on a budget → SnapStart; steady high volume that hates cold starts → move off serverless.

Takeaways


Sources: AWS Lambda Developer Guide (execution environment lifecycle, Init/Invoke/Shutdown phases, Provisioned Concurrency, SnapStart); the Firecracker NSDI 2020 paper and firecracker-microvm.github.io (microVM boot times); AWS Compute Blog on the September 2019 Hyperplane VPC networking change and on Lambda SnapStart internals; OpenJDK CRaC project (Coordinated Restore at Checkpoint). Representative timing figures are order-of-magnitude and vary with memory/vCPU allocation, dependencies, and region. Re-authored and deepened for this guide.

🤖 Don't fully get this? Learn it with Claude

Stuck on What are Cold Starts and Warm Starts, and Why Do They Matter for Performance? Open Claude, copy a block below, and it'll teach you this exact concept — visually and interactively.

🎨 Explain it visually

Build the mental picture, not memorization.

I just read a lesson on **What are Cold Starts and Warm Starts, and Why Do They Matter for Performance** (System Design) and want to truly understand it. Explain What are Cold Starts and Warm Starts, and Why Do They Matter for Performance from first principles using ONE vivid real-world analogy and a visual mental model — draw it as ASCII art or a clear step-by-step diagram — with a concrete example using real numbers. Then ask me one question to check I got the mental picture, and wait for my reply. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🤔 Walk me through it (interactive)

Socratic — adapts to where you're stuck.

Teach me **What are Cold Starts and Warm Starts, and Why Do They Matter for Performance** interactively. Ask me ONE guiding question at a time, wait for my answer, and adapt to my confusion — build the idea with me step by step instead of explaining it all at once. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧪 Quiz me & fix my gaps

Active recall exposes what you missed.

Quiz me on **What are Cold Starts and Warm Starts, and Why Do They Matter for Performance** with 5 questions, easy to tricky, ONE at a time. Tell me if each answer is right; at the end, explain clearly what I got wrong and why. If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.
🧠 Make it stick

Intuition + hook + flashcards for long-term memory.

Help me remember **What are Cold Starts and Warm Starts, and Why Do They Matter for Performance** for the long term: give the one-sentence intuition, a memorable hook/mnemonic, a tiny worked example, and 3 active-recall flashcards (Q -> A). If you're unsure or a claim isn't standard, say so and reason from first principles instead of guessing.

📝 My notes