HAProxy fulfills an important role in a highly available multi-master stack by ensuring that we always reach one writable node in a manner that prevents server flapping. Despite this, we have no way of politely managing traffic without another component. PgBouncer is that missing piece.
Beyond the pooling functionality that PgBouncer provides, the elements we really want to exploit are the RECONNECT and WAIT_CLOSE operations. By combining these two operations, we can put a BDR node into maintenance mode and allow any pending transactions to complete before working on the server.
This recipe will explain how to combine PgBouncer with HAProxy in a way that will ensure that there is literally no interruption in application traffic.