Skip to content
Get started
Get started
PostgreSQL Multi-Broker Examples
examples · postgresql · multi-broker

Three brokers. One database. Real work.

Build a disposable PostgreSQL 18.6 cluster, run three active bunqueue brokers, and exercise the public SDK across queues, workers, events, retries, the DLQ, shared limits, and durable job graphs.

PostgreSQL 18.6
authoritative state
/ | \
broker-a broker-b broker-c
producer TCP worker TCP observer TCP
\ | /
\------ public bunqueue SDK --/
multiple queues

All brokers use the same PostgreSQL URL and BUNQUEUE_POSTGRES_NAMESPACE. Each broker has a different, stable BUNQUEUE_BROKER_ID. Clients connect to a broker over TCP; they never connect directly to PostgreSQL.

From the repository root:

Terminal window
./examples/postgres-multibroker/verify.sh

The script creates a unique Compose project, runs each scenario separately with a 60-second deadline, and installs an exit trap before creating infrastructure. Success, failure, timeout, SIGINT, and SIGTERM all run ordered, independent resource and local-image removal attempts. Invalid project overrides are rejected before Docker is called.

The included topology uses three brokers because it is large enough to prove cross-broker behavior without hiding identities behind a load balancer. The same invariants apply to any supported fleet size:

SettingAcross the fleet
PostgreSQL URLSame authoritative database
NamespaceSame for shared queues; different to isolate environments
Broker IDUnique and stable per active broker process
TCP/HTTP portsMay be identical inside separate containers
PostgreSQL poolBudget brokers × poolSize, plus operational headroom
bunqueue versionKeep identical; mixed-version schema operation is not supported

Compose cannot safely scale one service definition when it contains one static broker ID. Declare instances explicitly, as this example does, or derive the ID from a stable orchestrator identity such as a Kubernetes Pod name.

This is a functional correctness example, not a benchmark. It proves real PostgreSQL persistence and multi-broker SDK behavior. It does not claim a production capacity number, test PostgreSQL primary failover, or replace the repository’s deeper crash, lease-fencing, contention, and model campaigns.

Next: build the Docker topology.