Operate and Scale N Brokers
- Docs
- SDKs, Recipes & Learning
- PostgreSQL Multi-Broker
- Operations
examples · production operations
Scale the fleet without breaking its invariants.
Client code stays identical. Reliable multi-broker fleets come from unique broker IDs, bounded PostgreSQL pools, readiness-gated routing, and clean rollouts.
Day-2 Fleet Operations
Probe /ready per pod, run doctor --pg <url>, and coordinate schema upgrades
BUNQUEUE_BROKER_ID, scrape /prometheus, and never mix binary versions across a schema bump.N-broker contract
Section titled “N-broker contract”| Invariant | Required configuration |
|---|---|
| Storage driver & URL | BUNQUEUE_STORAGE_DRIVER=postgres + same primary DB or HA endpoint |
| Namespace | Same BUNQUEUE_POSTGRES_NAMESPACE across brokers sharing queues |
| Broker ID | Unique, stable BUNQUEUE_BROKER_ID per active process (e.g., Pod name; never --scale a hardcoded ID) |
| Version | Same binary version for breaking bumps; mixed vN/vN+1 supported during additive expand rollouts (min_compatible_version <= vN) |
| SQLite path & clock | Unset / empty (DATA_PATH=''); PostgreSQL DB time governs leases |
Connection budget and traffic routing
Section titled “Connection budget and traffic routing”Each broker defaults to 4 pooled SQL connections plus 1 LISTEN channel:
required connections = (broker replicas * (pool size + 1)) + migrations/admin + monitoring/failover headroomTen brokers at pool size 4 use 50 connections before operational headroom. Larger pools can raise lock contention and WAL pressure; tune against real payloads and latency. Place one TCP service or L4 load balancer in front of /ready (200) brokers; because TCP balances per connection, monitor broker-local connection counts alongside global queue depth.
Security and observability
Section titled “Security and observability”- Security: keep PostgreSQL private with verified TLS (
sslmode=verify-full), inject credentials from a secret manager, enableAUTH_TOKENS, gate metrics withMETRICS_AUTH=true, terminate client TLS natively or at a trusted proxy, and run non-root. - Live fleet triage: point
bunqueue topat the single Service VIP to auto-discover PostgreSQL peers in[8] Nodes, or pass--nodes(BUNQUEUE_NODES) to poll brokers directly for summed throughput, tail latency, and per-node focus.
| Alert signal | Action trigger |
|---|---|
/ready | Broker stays non-ready past a brief DB blip |
| Queue depth & oldest age | Backlog grows beyond SLO |
| Lease recoveries & DLQ size | Frequent worker stalls or rising permanent failures |
| TCP command latency | Operations approach client commandTimeout |
| PostgreSQL pool, locks & WAL | Near max_connections, lock waits, vacuum lag, or replica lag |
Upgrades, backups, and pre-production drills
Section titled “Upgrades, backups, and pre-production drills”- Upgrades: both Queue and Workflow migration tables record
min_compatible_version. Additive expand releases (1 <= min_compatible_version <= vN) support zero-downtimeRollingUpdatewithout downgrading DDL (and existing v22/v2 databases backfill only the migrations column without locking live tables); breaking schema bumps (min_compatible_version > vN,<= 0, orNULL) fail closed—rehearse PITR restore on a clone, drain and stop old brokers, start one new broker to run the migration and verify counts, then start the remaining brokers at the same version. - Backups: use PostgreSQL-native physical backups and PITR (bunqueue’s SQLite S3 tool does not apply). PITR restores may replay jobs ACKed after the recovery point, so external side effects must be idempotent.
- Pre-launch drills: kill an active broker to verify lease recovery and stale-token fencing; reset DB connections to test client reconnect; fill and replay the DLQ; pause/resume across brokers; rehearse a PostgreSQL restore into a clean cluster.