I'm building a Patroni Postgres cluster; however, I can't decide which is the better architecture:

  • App > HAproxy > Pgbouncer > PostgreSQL (Patroni)
  • App > PGBouncer > HAproxy > PostgreSQL (Patroni)

I can't seem to get an answer upon my search and a lot of conflicted answers. Some say it's better to have haproxy in front and others say the opposite.

The cluster is for 40 small to mid-size DBs. The goal is to serve them, and I don't have much control over them or their behavior.


1 Answer 1


First option is what you want, because pgBouncer is a connection pooler for PostgreSQL. It needs to be close to DBMS and be one2one connected each one to its own Postgresql instance. As for HAProxy it is a load balancer, you can have HAProxies' number different than a number of Postgre\Patroni\pgBouncer instances. Plus it will give you an option to separate read and write requests to different ports\databases.

here is an article which will be helpful https://medium.com/@nicola.vitaly/setting-up-high-availability-postgresql-cluster-using-patroni-pgbouncer-docker-consul-and-95c70445b1b1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.