All posts
AWS Architecture

Lambda Cold Starts: What They Are, When They Matter, and How to Fix Them

By

November 20, 2024

8 min read

Cold starts are real. But they're often blamed for performance problems they didn't cause, and fixed with solutions that create bigger problems.

Lambda
Serverless
Performance
AWS

Cold starts are one of the most discussed serverless trade-offs. They're also one of the most misunderstood. In production systems, we've seen Lambda cold starts blamed for latency problems that turned out to be unoptimized database queries, and we've seen teams spend weeks on provisioned concurrency for workloads where cold starts weren't the bottleneck.

What actually happens during a cold start

When Lambda has no warm execution environment available, it must: download and unzip your deployment package, start the language runtime (JVM, Node.js, Python, etc.), run your initialization code (imports, database connections, SDK clients), and then execute your handler.

The time this takes varies dramatically by runtime. Node.js and Python cold starts are typically 100–500ms for a well-optimized function. Java with Spring Boot can be 5–15 seconds without optimization. This is the reason we recommend Node.js or Python for latency-sensitive serverless applications.

When cold starts actually matter

  • User-facing APIs where p99 latency is part of the SLA

  • Synchronous workflows where cold starts compound across multiple Lambda invocations

  • Spiky traffic patterns with long idle periods between bursts

  • Java/C++ runtimes where initialization time is measured in seconds, not milliseconds

Want a second opinion on this for your system?

Book a free 30-minute call. You'll leave knowing what we'd do first and roughly what it costs, whether or not you hire us.

When cold starts don't matter

  • Async workloads: SQS consumers, S3 event processors, EventBridge handlers — a few hundred ms of initialization is irrelevant

  • High-traffic APIs: with steady traffic, almost all invocations hit warm environments

  • Internal/background jobs where human users aren't waiting

  • Node.js/Python functions with lean dependency trees — cold starts are often under 200ms

The right solutions in order of preference

1. Optimize the function

Before anything else: reduce package size (tree-shaking, excluding dev dependencies), move SDK client initialization outside the handler (initialized once per warm container), and lazy-load expensive modules. A function that went from 50MB to 5MB and moved its DB connection pool outside the handler can drop cold start time by 60–80%.

2. Choose the right runtime

If you're starting fresh and cold start performance matters: Node.js or Python. If you must use Java, Lambda SnapStart (for Java 21) dramatically reduces initialization time by snapshotting a restored execution environment.

3. Provisioned Concurrency

Provisioned Concurrency keeps a specified number of execution environments pre-initialized. It works, but it costs money — you pay for the provisioned environments continuously, not per-invocation. Use Application Auto Scaling to provision based on a schedule (e.g., scale up before business hours, down at night) to reduce cost.

What to measure

CloudWatch Lambda Insights provides cold start metrics out of the box. Track: cold start frequency (what % of invocations are cold), cold start duration (p50, p95, p99), and — critically — what happens to those p99 end-to-end latencies. If cold starts are 2% of invocations and p99 latency meets your SLA, they're not your problem.

hoolco Monthly Review

Once a month: what changed in tech that month and what it means for you, from cloud and AI to security and the tools you build with. Every item links to its source. No sales pitch, unsubscribe in one click.

As of November 20, 2024. Provided as is, for general information, and accurate to the best of our knowledge on the date shown. Not legal, compliance, tax, financial or other professional advice. Prices, limits and vendor services change; check current vendor documentation before relying on anything here. Terms of use.