# Diagnosing slow cold starts with Upstash Redis
## Symptom
First request after idle takes seconds; subsequent requests are fast.
Worse on low-traffic functions that idle out constantly.
## Step 1: find where the client is created
If your handler constructs a new Redis client per invocation, every
cold start pays client construction plus the first TLS handshake and
token exchange. Move construction to module scope:
import { Redis } from "@upstash/redis";
export const redis = Redis.fromEnv();
export async function handler(req) {
return new Response(await redis.ping());
}
The SDK reuses connections across invocations on a warm instance.
## Step 2: check what else runs on cold start
- Top-level telemetry is one lightweight call, but you can disable
it with UPSTASH_DISABLE_TELEMETRY set to 1 if you are counting
milliseconds.
- Framework bootstraps (Next.js server components, ORMs) usually
dominate. Time the Redis client creation alone to see its share.
## Step 3: confirm
Log timestamps at module load, at handler entry, and after the first
Redis call. If module load dominates, it is client setup. If the
first Redis call dominates, it is the TLS handshake: consider
provisioned concurrency or a regional database closer to the
function.
## Fix and verify
Module-scope client, then re-measure cold start P99. The Redis
portion should drop to roughly one TLS handshake on true cold
starts and near zero on warm ones.