anselan
DTDrizzle Team
•Created by anselan on 9/30/2024 in #help
Advice for pooling DB connections with serverless
I have a great, working web application which uses SvelteKit, DrizzleORM, a PostgreSQL database running on Amazon RDS. It is hosted on Netlify, which means that the “backend” consists of one big serverless function (sveltekit-render) which handles all the SSR stuff that SvelteKit provides but also, crucially, makes a bunch of queries to the PostgreSQL database. I have a sort of custom-built HTTP REST API which is part of the same SvelteKit application.
I don’t have to worry about huge traffic volumes, but when we got a few hundred people to connect at once, the whole thing came crashing down because the DB hit its connection limit almost immediately (100+ connections).
I think that the issue is that Netlify spins up as many instances of the “sveltekit-render” function as it thinks is necessary - great for initial responsiveness of the site, but a nightmare for proliferating hundreds of simultaneous DB connections! Enabling the pooling feature provided by Drizzle (via postgres-nodejs) doesn’t really help much, because the instances of the “server” process don’t persist long enough to take much advantage of pooling, and in any case there isn’t any really anything to “share” between the instances anyway. At least, this is my understanding of the root cause.
Any thoughts on a good way to solve this problem? I could move away from Netlify entirely, and try to keep a single, more traditional single-server approach. At worst, this would slow down some parts of the site slightly, but would likely keep minimal database connections open (they could all be pooled for the single server). Or is there another way to keep the Netlify “serverless” architecture but somehow separate the SvelteKit “rendering” process from the “REST API” process, and get the API part to somehow handle more simultaneous requests, on a single (or very few) set of database connections?
43 replies
DTDrizzle Team
•Created by anselan on 5/22/2024 in #help
Drizzle Studio not updating schema but apparently applies it anyway?
I have added a simple one-to-one relation in my schema which is named
myGarden
(this links users
to an entry in gardens
).
In Drizzle Studio, this appears as a column in users
, and correctly links to an entry in the gardens
table. But when I try to run a query like
... I get a type error for myGarden
(doesn't exist) and if I click on the schema
tab I see that there is no relation named myGarden
, only garden
. I don't even know where this came from! (An older version of the shema? Where is it getting that from?)
To reiterate - Drizzle Studio seems to respect the new naming when displaying the table, and the query works just fine from my NodeJS server that uses Drizzle ORM. It's only Drizzle Studio, and its "Drizzle Runner" which refuses to acknowledge the changed relation as per the schema.1 replies