Max Connection Issue with Supabase + Vercel
I am running into max connection issues when I am using supabase within an application hosted in a serverless environment (vercel).
I've done everything I can find by the docs, but if I have a spike of 300+ users on my app at once, I start to run into a lot of max connection errors.
I am using trpc to help batch request and limit connections made. I create the postgres connection outside of drizzle, set max connections to 3, and pass the instance in.
I am using transaction mode in supabase so it uses supavisor.
I have prepared statements set to false.
Does anyone have any advice that might be harder to come by? Our team is considering swapping to a persistent server because we're running out of options as we're scaling quickly and keep running into connection issues w/ Supabase.
Thanks for any help!
3 Replies
welcome to postgres and serverless
most likely you want to add pgbouncer
wait, supabase has their own thingy already
you most likely want to run read copies of the database to distribute the load
and let the bouncer handle it
seems like most of the issues with it are around machine size
are you guys running a single instance?
Ya... it's been a painful welcome :sadCat:
We are using the Supabase built in bouncer/connection pooler
We do have one instance, using the XL machine size
You guys should use multiple nodes for that
One writer, multiple readers
Fly is building their own managed Postgres because supabase doesn’t have HA