Taming Lambda cold starts in a serverless backend
Practical techniques for reducing cold starts across a large serverless backend, from artifact size to provisioned concurrency.
- AWS
- Lambda
- Serverless
- Performance
When you operate a backend of dozens of Lambdas, cold starts stop being a novelty and start being a latency budget you have to manage. Here are the levers that moved the needle most for me.
Shrink the artifact
Cold start time scales with how much code the runtime has to load. A layered dependency strategy, tree-shaking, and pruning dev dependencies out of the bundle all reduce the unpack-and-initialize cost.
Pick the right runtime
Compiled runtimes like Go start fast and have small memory footprints. For latency sensitive paths, a Go handler routinely beats an equivalent interpreted one.
func handler(ctx context.Context, req events.APIGatewayV2HTTPRequest) (events.APIGatewayV2HTTPResponse, error) {
return events.APIGatewayV2HTTPResponse{StatusCode: 200, Body: "ok"}, nil
}
Reach for provisioned concurrency last
Provisioned concurrency eliminates cold starts but costs money around the clock. Use it only on the handful of endpoints where p99 latency genuinely matters, and lean on the cheaper techniques everywhere else.
The takeaway
Most cold-start pain is solved before you pay for provisioned concurrency: smaller artifacts, a fast runtime, and least-privilege functions that stay small.