Cluster-aware approach for YSQL with a nodejs postgres client?

Dear YugaByte team,

I’m building an application with a 3-node yugabyte cluster.
My cluster is deployed on AWS. I’m using nodejs in a serverless fashion.

The client library I’m using for YSQL is prisma2 but my problem is the same for any other postgres client library, I think.

Since there seems to be no way of telling the client library that there are three contact points for the database, I’m randomly choosing an IP-address from the three available when initializing the client.

Now, when one node goes down and stays down or is unreachable for whatever reason (which just happened to me) I face timeouts of my API because the client occasionally tries to connect to the node which is unreachable and does not fail fast and tries another one. The client is not aware of the cluster.

Now my question is: What is the recommended approach to handle this situation?

Do I need a Load-balancer and if so how do I set one up?
Is there a simpler way?

Thanks!

Hi @SebastianJ

Welcome to YugabyteDB Forum!

The recommended approach to handle this is to use a TCP Load Balancer.
In AWS, you can use a Network Load Balancer . Set the load balancer to target all yb-tserver nodes on the 5433 port.

Another way would be to use multiple hosts in the connection string when connecting. The client driver will automatically try hosts in order until one is up. It still won’t be aware when nodes go up/down though.

Regards,
Dorian
Technical Support Engineer

Hi,

thanks for the quick reply and the links! I’ll test both approaches.

Best regards,
Sebastian