Demo, all content is generated
Question

Every page on my Vercel app takes 1.5s+, Supabase is in Frankfurt

Solved · 3804 views · asked by pooja_s · edited

Next.js app, Supabase project in Frankfurt (eu-central-1), I'm in Amsterdam. Locally with the same remote database pages load in ~300ms. On Vercel every navigation takes 1.5 to 2 seconds. It's a small app, a dashboard page does maybe 4 queries. Cursor keeps adding loading spinners and useMemo but nothing changes.

What I’ve tried

Added indexes on user_id (Cursor's suggestion), used Promise.all for the 4 queries, checked the Supabase query performance tab (all queries under 5ms).

Comment
Where is your Vercel function region set to? abby_ops · edited
no idea, where do I see that? pooja_s · edited

3 answers

Marked as helpful by the asker
rafa_dev · edited

Check where your functions run: Project Settings → Functions → Function Region. The default is Washington D.C. (iad1). So every request goes Amsterdam → US East → Frankfurt for each query → back to US East → Amsterdam. Each transatlantic round trip is ~90ms, and your middleware auth check plus 4 queries (even in parallel, the auth one comes first) adds up fast.

Set it to Frankfurt:

// vercel.json
{
  "regions": ["fra1"]
}

or change it in the dashboard, then redeploy. Your queries being <5ms in Supabase was the clue: the time isn't in the database, it's in the distance.

Comment
1.8s -> 280ms. I spent a WEEK on indexes. Thank you so much pooja_s · edited
Keep the indexes, they'll matter when you have more data. rafa_dev · edited
+1 this saved me an hour, probably more. Same setup, same symptom. nightowl_nina · edited
Also applies to Supabase region choice when creating the project. Pick it next to where your functions will run, not where you live. sanne_dev · edited
lena_ops · edited

Also look at your middleware. If it calls supabase.auth.getUser() on every request, that's a network call to Supabase before your page even starts rendering. Keep it, it's the safe check, but scope the matcher so it doesn't run for static assets and public pages.

Comment
Scoped the matcher too, the public landing page is noticeably snappier. pooja_s · edited
ingrid_h · edited

Vercel Speed Insights (or the function logs) show TTFB per route. If TTFB is high and your queries are fast, it's almost always region or a waterfall of awaits.

Comment