Skip to content

perf: run database routes beside the database - #167

Merged
benthecoder merged 1 commit into
mainfrom
neon-region
Oct 28, 2026
Merged

benthecoder merged 1 commit into
mainfrom
neon-region

Conversation

@benthecoder

Copy link
Copy Markdown
Owner

Production search takes 1.4–3.4s per query, against ~250ms locally on the same database. The response header shows why: x-vercel-id: iad1::sin1. Requests enter Vercel's edge in Washington, but functions execute in sin1 (Singapore), the project's default function region, while Neon is in us-east-2 (Ohio). Every database round trip crosses the Pacific twice. Even keyword-only search, with no embedding call, took 1.5s.

This pins only the routes that talk to Neon to iad1 (about 10ms from us-east-2) with Next's per-route preferredRegion: /api/search, /api/thoughts, /thoughts (its hourly ISR regeneration queries Neon), /tweet and /api/tweet. Everything else keeps the project default. View counts use Upstash, whose region I can't see, so they're left alone.

Measurements from the [preview] deploy will follow in a comment. If you'd rather move the whole project, that's a Vercel dashboard setting (Settings → Functions → Region), but it affects every function.

tsc, 592 tests and knip pass.

til: x-vercel-id reads edge::function::id. The second hop is where your code ran, and a mismatch with your database's region costs a cross-ocean round trip per query.

@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
blog Ready Ready Preview Oct 28, 2026 3:43pm UTC

@benthecoder
benthecoder merged commit 3c77dc9 into main Oct 28, 2026
7 checks passed

This branch was successfully deployed

1 active deployment
Preview — 18e5903a Deployed Oct 28, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant