Connection Pooling
⚠ Work in Progress ⚠️
There's more to document here. In the meantime, you can check our community forum for answers.
Want to contribute? Redwood welcomes contributions and loves helping people become contributors. You can edit this doc here. If you have any questions, just ask for help! We're active on the forums and on discord.
Production Redwood apps should enable connection pooling in order to properly scale with your Serverless functions.
Prisma Data Proxy
The Prisma Data Proxy provides database connection management and pooling for Redwood apps using Prisma. It supports MySQL and Postgres databases in either the U.S. or EU regions.
To set up a Prisma Data Proxy, sign up for the Prisma Data Platform for free. In your onboarding workflow, plug in the connection URL for your database and choose your region. This will generate a connection string for your app. Then follow the instructions in Prisma's documentation.
Note that the example uses npm. Rather than using npm, you can access the Prisma CLI using
yarn redwood prisma
inside a Redwood app.
Prisma & PgBouncer
PgBouncer holds a connection pool to the database and proxies incoming client connections by sitting between Prisma Client and the database. This reduces the number of processes a database has to handle at any given time. PgBouncer passes on a limited number of connections to the database and queues additional connections for delivery when space becomes available.
To use Prisma Client with PgBouncer from a serverless function, add the ?pgbouncer=true
flag to the PostgreSQL connection URL:
postgresql://USER:PASSWORD@HOST:PORT/DATABASE?pgbouncer=true
Typically, your PgBouncer port will be 6543 which is different from the Postgres default of 5432.
Note that since Prisma Migrate uses database transactions to check out the current state of the database and the migrations table, if you attempt to run Prisma Migrate commands in any environment that uses PgBouncer for connection pooling, you might see an error.
To work around this issue, you must connect directly to the database rather than going through PgBouncer when migrating.
For more information on Prisma and PgBouncer, please refer to Prisma's Guide on Configuring Prisma Client with PgBouncer.