The latency geography checklist: 4,078ms → 384ms, step by step
The short version
The app took four seconds to open. The cause was geography: the server was in one continent and the database in another, so every single request crossed an ocean and came back.
Moving the database next to the server took it from four seconds to half a second, with zero changes to what the app does. One more change, not waiting on a write nobody was reading, took it to a third of a second. Ten times faster, no rewrite.
Copy these prompts
Paste them into Claude Code (or any AI that can see your project), in this order. Each one answers a different question, and the first is usually the one that matters.
1. Find out where each piece physically lives
Tell me which physical region each part of my app runs in: the server, the database, the cache and file storage. Put them in a table side by side and flag any that are not in the same region as the server.
2. Move them into the same place
Walk me through moving my database into the same region as my server, including how to verify nothing was lost, how to switch over, and how long I should keep the old one before deleting it.
3. Stop waiting on anything nobody reads
Find every place my app waits for something to be written before it responds, and tell me which of those the user never actually sees the result of. Show me how to let those happen in the background instead.
My app was slow for the dumbest possible reason: server in Virginia, database in Singapore.
That's 15,000 km apart. Every query paid ~200ms of pure ocean; every fresh connection paid
~1.3s (TLS + auth handshakes × cross-region). Cold start measured in Sentry: 4,078ms.
After pg_dump | pg_restore to us-east-1: 502ms. After deferring one write off the
critical path: 384ms. That's 10× from moving bytes closer, before touching a line of
query logic.
The checklist
- Check your regions before you touch your code. List where each piece actually runs:
functions (Vercel defaults to
iad1/us-east), DB, Redis, storage. Mine drifted apart because each was created with its own "default region" dropdown. - Measure with a trace, not a guess. One distributed trace of a cold request showed the shape instantly: dozens of ~200ms DB spans + a 1.3s connect span. Without tracing I'd have "optimized" queries that were fine.
- Do the RTT math. Cross-Pacific RTT ≈ 200ms. A request doing 10 sequential queries = 2s of geography. No index fixes that.
- Move the database, not the app. The migration was one evening:
# create new project/DB in the server's region, then:
pg_dump --format=custom "$OLD_URL" \
| pg_restore --no-owner --no-acl --clean --if-exists -d "$NEW_URL"
# verify row counts match on key tables, flip DATABASE_URL, delete old
- Verify, then cut over cheaply. Row-count comparison on every table, one env-var flip
(
DATABASE_URL), keep the old DB until traces confirm. In-region result: 2-5ms per query, ~30ms fresh handshake. - Then take the free second win: get writes off the critical path. My
UPDATE users SET last_seen_atran on every authenticated request. Fire-and-forget (void db.update(...).catch(log)) took the trace from 502ms → 384ms. - Re-check after every new service. Each managed add-on (queue, vector DB, cache) re-rolls the region dice. Put "same region as the API" in your provisioning checklist.
- Colocate cache with compute too. A Redis 200ms away is slower than no Redis for small reads.
Steal this for your app
- Latency budget rule: geography first, connection reuse second, queries third. Most people work that list backwards.
- If you're on serverless functions, cold-start pain is multiplied by cross-region: every cold instance pays the full handshake tax. Colocating fixes both at once.
- Screenshot your before/after trace. 4,078 → 384 is the cheapest 10× you'll ever ship, and the receipt is great for morale (and reels).
Run this on your codebase
Paste this into Claude Code in your repo:
Audit this repo for cross-region latency traps.
List every external service we connect to (Postgres, Redis, storage, queues, vector DB) and the region each runs in, from config files, env var names, and connection strings.
Identify the region our compute runs in (vercel.json, fly.toml, serverless config, Dockerfiles).
Flag any service in a different region than the compute and estimate the RTT tax per round trip.
Find request paths that issue sequential queries in a loop and multiply the count by that RTT.
Find writes on the hot path (last_seen style updates) that could be fire-and-forget.
Report findings as a checklist before changing anything.