Prompt
serverless API latency too high
Latest observation
Oct 25, 2026
OpenAI APIWeb search: off
High latency in a serverless API is usually caused by one or more of these:
Common causes
-
Cold starts
- Function hasn’t run recently, so the platform has to initialize it.
- Worse with large dependencies, VPC access, or certain runtimes.
-
Slow downstream services
- Database queries, external APIs, queues, auth providers, etc.
- Serverless often exposes these delays more clearly.
-
Too much work per request
- Heavy JSON processing, image/file handling, encryption, large payloads.
-
Inefficient database access
- No connection pooling strategy, N+1 queries, missing indexes, chatty ORM usage.
-
Networking/VPC overhead
- Lambda/VPC-style setups can add latency, especially to RDS or private services if misconfigured.
-
Large deployment package
- Slow initialization because the code bundle is huge.
-
Wrong memory/CPU sizing
- Under-provisioned memory can mean less CPU, slower execution.
-
Cold caches
- Cache misses in Redis/CDN/app layer.
What to measure first
- Cold start vs warm start latency
- P50 / P95 / P99 response times
- Breakdown by stage
- initialization
- handler execution
- DB call
- external API call
- serialization
- Invocation logs / traces
- Use OpenTelemetry, X-Ray, Datadog, New Relic, etc.
Quick wins
- Increase function memory to get more CPU
- Shrink deployment bundle
- Reuse DB connections carefully
- Add caching
- Reduce external calls per request
- Optimize slow queries and add indexes
- Move heavy initialization outside request path
- Avoid unnecessary VPC placement if possible
- Use provisioned concurrency / warmers if cold starts are the main issue
If you want to troubleshoot systematically
- Compare cold and warm invocation times
- Add timing logs around each major step
- Trace one slow request end-to-end
- Identify whether the bottleneck is:
- compute
- network
- database
- init/cold start
- Optimize the biggest contributor first
If you’re on AWS Lambda specifically
- Consider:
- Provisioned Concurrency
- More memory
- Smaller package
- RDS Proxy
- Avoiding unnecessary VPC attachment
- ARM64 runtime
- SnapStart for supported runtimes (Java)
If you want, I can help you diagnose it more precisely if you tell me:
- cloud provider
- runtime/language
- average and P95 latency
- whether it happens only on first request
- whether you use a DB or external API