Load-balancing PostgreSQL queries using two different Spring datasources

1/24/2017

We're attempting to set up a PostgreSQL cluster using streaming replication inside Kubernetes, but we'd prefer to avoid the trouble of going through the configuration of pgpool or any other SQL-aware load-balancers.

That being said, I'd like to ask whether it is a good idea at all to configure Spring Boot to use two datasources in the following way:

  • The first (@Primary) datasource would point towards the current PostgreSQL master and be used for read and write operations.
  • The second datasource would point towards a hot-standby replica and be used for read operations.

Provided that there are Kubernetes services that point to the current master and to the read replicas, and that failover is not automated, are there any risks in this approach?

-- Tony E. Stark
java
kubernetes
postgresql
replication
spring-boot

0 Answers