Skip to content
$EngineeringAtlas

Cutting Cold Starts in Serverless

Practical levers for trimming that first-request latency.

Amit Kumar Singh2 min read

The Problem

Serverless platforms scale down idle functions, so the first request may pay for container start, runtime boot, dependency loading, and application initialization.

Why It Matters

Cold starts are most visible on low-traffic but important paths: admin dashboards, checkout callbacks, internal tools, and webhook handlers. The system may look fast in average latency while a few users regularly hit multi-second startup delays.

AWS Lambda, Google Cloud Run, Azure Functions, and Vercel all have some form of startup behavior. The exact knobs differ, but the engineering trade-off is the same: pay for warm capacity or design the endpoint to tolerate startup latency.

Project Example

A Java or Next.js API endpoint may be fast when warm but take seconds after a quiet period. Users experience this as random slowness, especially on low-traffic admin tools, checkout callbacks, or webhook endpoints.

Implementation Example

For a Node.js API route, avoid creating expensive clients inside the handler:

const db = createDbClient(process.env.DATABASE_URL);

export async function POST(request: Request) {
  const body = await request.json();
  return Response.json(await db.orders.create(body));
}

This allows the runtime to reuse the client across warm invocations. The same idea applies to SDK clients, HTTP agents, model clients, and connection pools.

Implementation Checklist

  • Keep dependencies and bundle size small.
  • Move non-critical initialization out of the request path.
  • Reuse database clients across invocations.
  • Use provisioned concurrency or min instances for critical endpoints.
  • Measure cold and warm latency separately.
  • Split heavy admin/reporting code away from latency-sensitive APIs.
  • Lazy-load optional SDKs only when needed.
  • Add timeout and retry behavior for first-request startup paths.

Production Notes

For user-facing endpoints, track cold-start frequency and p95 or p99 latency. If only one request per hour is slow, a warm instance may be cheaper than debugging every millisecond. For high-volume APIs, the bigger issue is often database connection reuse and burst scaling.

Common Mistakes

  • Optimizing warm p50 while ignoring cold p95.
  • Opening a new database connection per invocation.
  • Loading large SDKs for one small call.
  • Using serverless for latency-critical paths without a warm capacity plan.
  • Bundling unused routes, dependencies, or large assets into every function.

Summary

Cold starts are manageable when measured directly. Reduce startup work, reuse clients, and pay for warmth only where user experience requires it.

Amit Kumar Singh

// written by

Amit Kumar Singh

Software engineer writing about backend systems, cloud, and the realities of running code in production.

$ subscribe --weekly

The weekly engineering digest

Production-grade engineering writing in your inbox. No spam, unsubscribe anytime.

## related