Insights

How we strengthened our broker with hot-on backups on new ports

Two replicas on 18801 and 18802, nginx least_conn in front, drift cron every 30 minutes — the structural change that took the Pryzm LLM broker from single-instance to hot-swap HA.

All insights
7 min read

For months the Pryzm LLM broker ran as a single process on :18800. When it went down, customers saw 502s on api.pryzm.at — and the manual fix was always the same: ssh in, restart the container, apologise. We replaced that with two replicas on :18801 and :18802, nginx least_conn in front, and a drift cron that fails the host closed the moment the live config drifts from the repo. This post is the engineering story behind the change, the commands it ran on the way, and the lessons we want every self-hosted AI platform to inherit.

Replicas
2 (a + b)
Broker ports
18801 / 18802
Upstream strategy
nginx least_conn
Failover trigger
error / 502 / 503 / 504
Drift check
every 30 min
Config source-of-truth
infra/nginx/hosts/*

The single-broker failure mode

Until August 2026 the Pryzm LLM broker ran as one container: pryzm-llm-broker on :18800. api.pryzm.at had a proxy_pass block that pointed at that one upstream. When the container restarted — for any reason, planned or not — every chat completion, embedding, and health probe routed to api.pryzm.at saw the error.

It worked most of the time. The moments it did not work were exactly the moments customers paid us to be reliable: a model swap, an Ollama-discovery hiccup, a Docker prune, a node reboot. A single point of failure dressed up as a service.

We had been promising our customers that the broker is hot-swappable for a while. We were lying. There was no second replica, no failover, no drift check — just a single process and a manual restart.

  • Single process on :18800 — no peer to take over
  • Manual `docker compose up -d` on the host when it fell over
  • 16 hours of /broker/* shadowed by the SPA catch-all in one incident
  • Customer-visible 502s during every restart, planned or not

Two replicas, two new ports

The first move was structural: stand up a second replica on a new port, then a third on a third port if we need it. We picked :18801 and :18802 as the new home for the HA replicas — pryzm-llm-broker-a and pryzm-llm-broker-b — leaving :18800 alone for the legacy single-instance path while we ran both side by side.

Each replica is the same container image, the same model bundle, the same vault credentials. They differ only in hostname and port. That is deliberate: identical config means identical failure modes, which means our failover logic exercises every bug once, not once per replica.

Once both replicas were healthy — both answering /v1/models with the same model catalogue, both signing JWTs with the same audience — we put nginx in front of them. api.pryzm.at's upstream block went from `server 127.0.0.1:18800` to a `pryzmat_llm_broker` upstream with `least_conn` over the two new ports.

  • pryzm-llm-broker-a on 127.0.0.1:18801 (max_fails=2, fail_timeout=10s)
  • pryzm-llm-broker-b on 127.0.0.1:18802 (max_fails=2, fail_timeout=10s)
  • keepalive 64 — long-lived connections from the agent runtime
  • Identical config + identical model bundle on both — no per-replica tuning

Hot-on, not hot-swap

We call this hot-on, not hot-swap, because both replicas stay running and accept traffic at all times. There is no warm standby, no promotion step, no switching — the moment one replica goes unhealthy, nginx routes the next request to the peer. That is the entire failover story.

The triggers are deliberately narrow: error, timeout, http_502, http_503, http_504. We do NOT fail over on 4xx — a malformed request to a healthy upstream should not move traffic to the peer. We set `proxy_next_upstream_tries 2` and `proxy_next_upstream_timeout 15s` so the failover is bounded: a request tries the failing replica once, then the peer, and either succeeds or surfaces the error to the caller within 15 seconds.

For long-lived streaming — /broker/v1/chat/completions — we disable buffering, raise read_timeout to 1200 seconds, and keep the same failover rules. A 20-minute deep-research stream that hits a 30-second hiccup on the active replica will land cleanly on the peer without the customer noticing the failover.

Repo as the single source of truth

The structural change is not just two replicas. It is the rule that infra/nginx/hosts/api.pryzm.at.conf is the source of truth for the live host nginx config. Until JAISIU-2292, the live /etc/nginx/sites-enabled/api.pryzm.at was edited by hand, the repo copy was a 'reference only', and the two drifted.

scripts/infra/sync-host-nginx.sh is the fix. It copies every conf under infra/nginx/hosts/ into /etc/nginx/sites-available/, recreates the sites-enabled symlink, runs `nginx -t`, and reloads nginx only if the test passes. There is a --check mode that exits non-zero on drift, and a companion script — check-host-nginx-drift.sh — that we wired into the host's crontab at */30 * * * *.

If a human (or a model) edits the live nginx config out of band, the next 30-minute tick fails the drift check and the operator gets a log line. The repo, the host, and the cron form a triangle that converges on the same config every half hour.

  • sync-host-nginx.sh --check: exit 1 if repo and host disagree
  • check-host-nginx-drift.sh: log + alert operator, fail closed
  • Cron line: */30 * * * * bash /root/jaisiu/scripts/infra/check-host-nginx-drift.sh
  • Default sync allow-list: pryzm.at + api.pryzm.at (extend with --include=<host>)

What we learned (and what we want you to inherit)

The biggest lesson is that 'production' is not a config file. It is a chain of evidence — repo, build, deploy, host, cron, alert — that the live system matches the system the team committed to. The moment any link in that chain becomes 'reference only' or 'manual fix', the chain breaks silently and the customer discovers it.

The second lesson is that hot-on HA is cheap when the load balancer already exists. Two replicas behind nginx cost the same as one — the only new spend is the second broker's memory and a couple of extra health probes. There is no replication protocol, no leader election, no consensus. nginx does the work.

The third lesson is that the drift check matters more than the deploy script. The deploy script is run on purpose; the drift check is run by a clock, and that is what catches the silent regressions (the 16-hour /broker/* shadow we lost in August was a drift, not a deploy).

  • Hot-on HA is the default — not the upgrade path
  • The drift check is the actual reliability primitive, not the deploy script
  • Identical replicas > clever per-replica tuning — one bug, one fix
  • Repo + host + cron = production. Anything 'reference only' is a future incident.
  • Broker
  • HA
  • Nginx
  • Reliability
  • api.pryzm.at