Group
  • Performance

    Reduce my serverless cold start latency

    Find what's making your functions slow to wake up and trim initialization, dependencies, and bundle weight.

    • Improve quality
    • Debug & fix
    • Intermediate
    • General

Free Prompt

My app runs on serverless functions and some requests take seconds to respond after idle periods. Cold starts are making my app feel randomly slow. Diagnose and reduce my cold start latency: 1. Confirm it's actually cold starts: compare response times for the first request after idle versus warm requests. If the gap is small, the problem is elsewhere; tell me and stop. 2. Audit what happens at initialization: what modules load at the top level, what connections open (database, cache, third-party clients), what config parses, what large dependencies get imported. Heavy imports at module scope run on every cold start even when the request doesn't need them. 3. Trim the function bundle: remove unused dependencies, replace heavy libraries with lighter ones where the heavy one isn't pulling its weight, and make sure I'm not bundling dev dependencies into production deploys. 4. Lazy-load what's request-specific: move imports and client setup that only some code paths need into those paths, and reuse connections across warm invocations instead of reconnecting per request. 5. Consider the platform levers last: provisioned concurrency or keep-warm pings for the few latency-critical routes (checkout, login), with a note on what each costs. Don't keep-warm everything; that's paying to hide a problem instead of fixing it. 6. Check my database access pattern for serverless: per-invocation connection creation against a database with a connection limit will cause failures under concurrency; use the platform's recommended pooling approach. Don't add keep-warm hacks before trimming initialization; measure first so I know what the cold start actually costs. The deliverable is the diagnosis, the initialization and dependency changes, and before/after cold-start timings per affected route.

What This Does / How This Helps

This confirms whether cold starts are really your latency problem, then attacks the causes: heavy module-scope imports, fat dependencies, eager connections, and per-invocation database connection creation. Cold starts make an app feel haunted: fast most of the time, then a three-second hang for the unlucky user who hits an idle function. For a low-traffic pre-launch app, that's a lot of your early users, since functions idle constantly at low volume. The fixes are mostly boring initialization hygiene, and they also reduce the chance you hit connection-limit failures the moment real concurrency arrives.

Want to skip doing this by hand?

Fortivibe audits your app for all of the areas these prompts cover (and more).

See What We Check

Related Prompts