# Diagnosing Upstash Redis latency

## Symptom

P50 looks fine, P99 is bad, or every call takes 50ms+ from your app.

## Step 1: know the baseline

Upstash publishes internal p99s for reference: reads from the same
region under 1ms, writes under 5ms, same-continent under 50ms. Measure
yours against these.

## Step 2: check region placement

- Your app and database should be in the same region. A Lambda in
  us-west-2 talking to a database in eu-west-1 pays cross-continent
  latency on every call.
- On a Global database, reads route to the nearest read region but
  writes always go to the primary region first. If your writes come
  from far away, move the primary region to where the writes happen.
- Global databases optimize reads. A write-heavy workload on a Global
database will always be slower than on a regional one.

## Step 3: count round trips

One REST call is one HTTP round trip plus TLS. Ten sequential awaits
is ten round trips:

const a = await redis.get("a");
const b = await redis.get("b");

Batch them:

const [a, b] = await Promise.all([redis.get("a"), redis.get("b")]);

Or use /pipeline for raw REST. Pipelining trades per-command latency
(each command takes as long as the whole batch) for total throughput.

## Step 4: confirm

Time a single PING from your app host. If PING is slow, it is network
or region placement. If PING is fast but your flow is slow, it is round
trip count.

## Fix and verify

Move the database or the app into the same region, batch the calls,
and re-measure P99. Expect same-region P99 near the published
baselines.