Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Vercel serverless functions causing database connection exhaustion #2639

Closed
flacial opened this issue Dec 23, 2022 · 1 comment
Closed

Vercel serverless functions causing database connection exhaustion #2639

flacial opened this issue Dec 23, 2022 · 1 comment

Comments

@flacial
Copy link
Member

flacial commented Dec 23, 2022

Description

Based on the analysis made by @JasirZaeem, we noticed we have been experiencing issues with our Vercel serverless function exhausting the database connections and causing the database to reach the maximum connections limit. This has resulted in errors and downtime for our application.

Upon further investigation, we have identified that the issue is caused by our Vercel serverless function making too many connections to the database in a short period of time. This is likely due to the high volume of requests being sent to the function, which is causing it to create a new connection for each request.

We believe that implementing a connection pooling solution, such as pgbouncer, could help resolve this issue. Connection pooling allows multiple connections to be grouped into a single "pool" and shared among multiple clients. This can help reduce the number of connections made to the database, as well as improve the performance and scalability of our application.

Steps to reproduce

  1. Send a high volume of requests to the Vercel serverless function
  2. Observe the database reaching the maximum connections limit and errors being thrown

Expected behavior

The Vercel serverless function should be able to handle the high volume of requests without exhausting the database connections and causing errors.

Actual behavior

The Vercel serverless function is causing the database to reach the maximum connections limit and throwing errors.

Solution

Implementing a connection pooling solution, such as pgbouncer, could help resolve this issue by reducing the number of connections made to the database and improving the performance and scalability of our application.

Resources

@JasirZaeem
Copy link
Member

Pgbouncer has been setup on server and the PR has been merged. To tell the app to use the databse through pgbouncer add USE_POOLED_DB as an environment variable with the value 1 at vercel and redeploy it whenever needed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🦄 Done
Development

No branches or pull requests

2 participants