Very slow response time for requests via BlitzJs RPC layer (NextJs)


I am facing a performance issue when deploying my app in production.
All the requests to the database take about 2 to 5 seconds, which is abnormally long.

I think the error comes from Netlify hosting, because when I make requests to my production database from localhost, I get normal response time (from 40ms to 500ms).

My stack:

  • For the database I am using a cloud hosted version (AWS eu-central-1) of Supabase (it is not self-hosted, so should not be a performance issue on that side)
  • For the frontend, I’m using BlitzJs, which is a toolkit for NextJs
  • BlitzJs exposes a RPC layer that, in turn, make requests to the database, using Prisma

Could there be an issue using RPC layer in a Netlify hosted app?

On the other side, my requests are authenticated with a cookie (not a JWT).
I have read that such requests could not be cached by Netlify, and had to travel to the us every time.
But would it justify such a long response time (more than 2sec)?

Thank you in advance for your help :slightly_smiling_face:

PS: I cannot share the website name publicly, as it’s a project for a client, ask me by private message if you need to see it

So, for whomever encounter the same latency issue for requests to his database in production, here is the solution:

You have to know that NextJs api routes are deployed as serverless function on Netlify (or Vercel). Those functions are hosted by default in the USA.

To avoid latency, you should ask the support to move your functions as close as your database.

In my case, I asked them to move the functions to eu-central-1 and it solved my latency issue.

Hope this helps :slight_smile: