Another great way of abstracting PostgreSQL is to place it behind a proxy to redirect traffic to the primary read/write node in our cluster. One of the most popular of these proxies is HAProxy, a generic proxy software that was originally designed for load balancing web servers.
It's also a highly versatile layer that we'll be using in several other recipes in this book. Not only does it ensure we always reach the primary node regardless of its location, but we can also leverage its functionality to spread read queries across multiple PostgreSQL replicas.
This recipe will explain the basic installation of this high-availability connection proxy, which we can then extend later on.