Hub HA and failover
Multiple Hub processes can share one PostgreSQL database and elect exactly one leader through a lease row. This runbook takes you from a single Hub to an HA pair, verifies a failover, and rolls back safely.
Use when: the control plane is a single point of failure for fleet
operations and a few seconds of 503 during failover is acceptable. The data
plane (streams and Jobs already running on Agents) keeps running throughout.
Impact. During a takeover, operator and agent routes answer 503 for up to
the lease TTL plus one probe (default ≈ 15 s + 5 s). Agents reconnect
automatically; the data plane is not restarted.
Prerequisites
- A PostgreSQL database reachable from every Hub (
postgres://URL). - NTP-aligned clocks on every Hub and the database host — the lease TTL must dwarf clock skew.
- The same
ARKFLOW_OPERATOR_TOKENandARKFLOW_NODE_TOKENsemantics on every instance (use a secret reference for real deployments). - A load balancer or VIP in front of the Hubs for operator and console traffic (optional for Agents, which follow the leader themselves).
Steps
-
Back up the current store before changing topology:
arkflow-server backup --from <store> --to <snapshot-file>. -
Point every Hub at the same PostgreSQL URL with
ARKFLOW_HUB_STORAGE. -
Enable election on every instance:
Variable Value ARKFLOW_HUB_HA_ENABLEDtrueARKFLOW_HUB_HA_ADVERTISE_URLAbsolute http(s)://host:portof this instanceARKFLOW_HUB_HA_LEASE_TTL_MSLeave default 15000unless you have measured a needARKFLOW_HUB_HA_HOLDER_IDLeave unset; the default host:pid:boot-msis unique -
Start the instances. One wins the lease; every other process serves only
/health,/readiness,/liveness, and the metrics export. -
Verify the leader:
curl -s http://hub-a:8080/api/v1/system | jq '.ha'
curl -s http://hub-b:8080/readiness | jqThe leader reports
role: leaderand a fencing epoch; standbys report503 hub_standbyon/api/v1/systemwith aleader_urlhint when advertised. -
Fail over deliberately by stopping the leader gracefully (SIGTERM). The lease is released immediately instead of waiting for the TTL. Confirm the standby's epoch increased, Agents re-registered, and a harmless write succeeds.
Verification
/api/v1/systemshows exactly oneleaderand an increasingha.epoch.- Agents report the new Hub (
connected_hub) and their failover counter advances in logs/metrics. - A queued write succeeds after the standby is promoted; a write that raced the
takeover may return
503 stale_leaderand must be retried. - The event stream contains
hub.leadershiptransitions.
Rollback
- Stop every Hub.
- Remove
ARKFLOW_HUB_HA_ENABLED(or set it tofalse) and start one Hub against the same PostgreSQL database. It runs unfenced, as a single instance. - Keep the remaining instances stopped; a second unfenced Hub would serve stale in-memory views.
- If the topology change itself caused the incident, restore the pre-change backup into an empty store and point the single Hub at it.
Degradation and failure modes
| Situation | Behavior | Action |
|---|---|---|
| Leader loses the lease or storage | Steps down immediately, stops dispatching. | Restore storage/network; the election promotes a standby. |
| Split brain suspected | Fencing epochs reject stale-leader writes with 503 stale_leader. | Do not disable fencing; fix the network or storage partition. |
| SQLite configured with HA enabled | Logs a warning; HA requires PostgreSQL. | Migrate with arkflow-server migrate before enabling HA. |
| Two Hubs share a holder id | They renew each other's lease and both act as leader. | Leave ARKFLOW_HUB_HA_HOLDER_ID unset. |
Observability
GET /api/v1/system—ha.role,ha.epoch.- Event stream —
hub.leadership. - Hub logs — lease renewal failures, step-down, takeover reload.
/metrics— standby metrics remain scrapeable.