Khaldoun Mattar
Khaldoun Mattar

Reputation: 31

Does more instances means more connections?

I am trying to build a messaging app such that each message will be inserted to the database. Also, my backend will hit the database every second to retrieve the latest messages. I am worried that if I have many users who are using the messages feature, I will hit the database maximum number of connection quickly and the app will not work for other users. So, how can I make sure this problem will not happen?

https://cloud.google.com/sql/pricing#2nd-gen-instance-pricing

Upvotes: 0

Views: 73

Answers (1)

kurtisvg
kurtisvg

Reputation: 3565

You shouldn't have a unique connection per user to your database. Instead, your backend should use connection pooling to maintain a consistent number of connections to your instance. You can view some example of how best to do this on the Managing Database Connections page.

It's incredibly unlikely that you'll need 1000 open connections. Most applications use far, far less for optimal performance. You can check out this article about benchmarking different connection pool sizes.

Upvotes: 1

Related Questions