Skip to main content
Version: Next

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_TOKEN and ARKFLOW_NODE_TOKEN semantics 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​

  1. Back up the current store before changing topology: arkflow-server backup --from <store> --to <snapshot-file>.

  2. Point every Hub at the same PostgreSQL URL with ARKFLOW_HUB_STORAGE.

  3. Enable election on every instance:

    VariableValue
    ARKFLOW_HUB_HA_ENABLEDtrue
    ARKFLOW_HUB_HA_ADVERTISE_URLAbsolute http(s)://host:port of this instance
    ARKFLOW_HUB_HA_LEASE_TTL_MSLeave default 15000 unless you have measured a need
    ARKFLOW_HUB_HA_HOLDER_IDLeave unset; the default host:pid:boot-ms is unique
  4. Start the instances. One wins the lease; every other process serves only /health, /readiness, /liveness, and the metrics export.

  5. Verify the leader:

    curl -s http://hub-a:8080/api/v1/system | jq '.ha'
    curl -s http://hub-b:8080/readiness | jq

    The leader reports role: leader and a fencing epoch; standbys report 503 hub_standby on /api/v1/system with a leader_url hint when advertised.

  6. 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/system shows exactly one leader and an increasing ha.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_leader and must be retried.
  • The event stream contains hub.leadership transitions.

Rollback​

  1. Stop every Hub.
  2. Remove ARKFLOW_HUB_HA_ENABLED (or set it to false) and start one Hub against the same PostgreSQL database. It runs unfenced, as a single instance.
  3. Keep the remaining instances stopped; a second unfenced Hub would serve stale in-memory views.
  4. 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​

SituationBehaviorAction
Leader loses the lease or storageSteps down immediately, stops dispatching.Restore storage/network; the election promotes a standby.
Split brain suspectedFencing epochs reject stale-leader writes with 503 stale_leader.Do not disable fencing; fix the network or storage partition.
SQLite configured with HA enabledLogs a warning; HA requires PostgreSQL.Migrate with arkflow-server migrate before enabling HA.
Two Hubs share a holder idThey 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.