High availability and scale¶
High availability¶
Set ha: true and replicas: 2 (or more). Requirements, enforced at start-up:
- PostgreSQL as the database;
- the Kubernetes backend — HA mode rejects local and SSH execution environments;
- every controller uses the same database, namespace, images, Terraform key and settings.
What the chart changes in HA mode: the controller's /data becomes a per-pod emptyDir instead of a shared volume, pods prefer different nodes (anti-affinity), and a PodDisruptionBudget keeps at least one controller during voluntary disruptions.
How controllers cooperate¶
All controllers serve the UI and API and all run the scheduler. They coordinate only through PostgreSQL:
- Per-run locks. Reconciling, canceling and approving a run take a lock on that run alone. A slow run never blocks others. branch codex/highload-s3
- Global runner limit. A short transaction lock reserves a runner slot and records the intent to start a step before any Kubernetes call.
maxParalleltherefore holds across all replicas. - Stable Job names. A step's Kubernetes Job name is fixed when the run is created. If a controller dies after creating a Job, the next one finds the same Job instead of creating a second.
- Fail closed. If a controller loses its database lock session, it stops writing for that run instead of silently reconnecting. Another controller takes over once PostgreSQL releases the old session.
- Resource locks. Saving, syncing or deleting a project or inventory takes a lock on that resource.
The cache never takes part in coordination or leader election.
What survives what¶
| Failure | Effect |
|---|---|
| One controller pod dies | Others continue; its in-flight API requests fail and can be retried |
| All controllers restart | Running runner pods continue; controllers resume from PostgreSQL |
| PostgreSQL unavailable | Scheduling, API and capture pause; runner pods may finish; Terraform applies cannot save state |
| Cache unavailable | Reads fall back to PostgreSQL, retried after 5 seconds |
| Log worker dies | Another worker takes the lease after ≤ 90 seconds and resumes |
| A node with a runner dies | That step fails (no automatic retry); output not yet captured may be lost |
Controller HA does not make PostgreSQL, Vault, the cache or Kubernetes highly available — plan those separately.
Exactly-once is not guaranteed
Liftway never launches a step twice on purpose, but Kubernetes cannot promise that a process ran exactly once on a target. Write idempotent playbooks. Project or inventory syncs interrupted by a crash may run again (they only read Git).
Upgrading into the scoped scheduler¶
Versions before the scoped scheduler used one global lock and kept no runner-slot ledger. Old and new controllers must not run side by side. Keep controllerStrategy: Recreate for that first upgrade; it stops all old pods before new ones start (a short API interruption; running runner Jobs continue). Afterwards you may switch to RollingUpdate.
Capacity settings¶
| Setting | Default | What it limits |
|---|---|---|
maxParallel |
4 | Steps in starting or running, installation-wide |
schedulerWorkers |
8 (1–32) | Runs reconciled in parallel per controller, every 2 seconds |
database.poolSize |
8 | Pooled database connections per controller |
RUNWAY_COORDINATOR_CONNECTIONS |
16 | Extra lock sessions per controller (environment variable) |
logWorker.replicas / capacity / poolSize |
1 / 100 / 8 | Output capture |
cache.ttl |
60 s | Cache freshness |
When the database pool is exhausted (64 waiting requests or 5 seconds), and when a lock cannot be taken within 5 seconds, the API answers 503 with Retry-After: 2 rather than hanging. Clients should retry.
Database connections needed: (poolSize + 16) × controllers + logWorker.poolSize × log workers, plus headroom for migrations and administrators. Connect directly or through a session-mode pooler.
What large installations need¶
| Area | Recommendation |
|---|---|
| Runner limit | Raise maxParallel in steps while watching Kubernetes API latency, node capacity and target load |
| Log volume | Use S3 log storage; run ≥ 2 log workers |
| History | Enable retention; the Jobs list and dashboard are paged and aggregated in SQL |
| Cache | An external Dragonfly or Valkey speeds up host catalogues and counts on large inventories |
| PostgreSQL | Managed HA (e.g. Crunchy PGO), point-in-time recovery, enough IOPS for output ingest |
| Isolation | Separate installations (namespaces, Vault roles) for teams that must not share credentials |
Reference measurements¶
On a single-node local k3d cluster — not a production benchmark — with two controllers, one log worker, maxParallel 4, 5,000 synthetic hosts, 100 templates and more than 10,000 runs in history:
| Scenario | Result |
|---|---|
| 24 workflows submitted at once, 48 runner Jobs | All successful; never more than 4 slots in use |
| Output | 480,000 lines verified line by line; 1,896 S3 chunks; no hot rows left |
| Jobs list under load (10 parallel readers) | p50 86 ms, p95 164 ms |
| Dashboard under load, cold 5,000-host count | p50 115 ms, p95 2.97 s |
| Log worker killed mid-stream, S3 stopped | 12,000 lines recovered in order, no loss or duplicates |
No real SSH connections were made to 5,000 hosts, and PostgreSQL or node failure was not tested. Define your own targets and run a soak test on staging-like infrastructure before relying on numbers.
Known limits¶
- Some administrative mutations, manual syncs and scheduled maintenance still share one coordination lock; a slow Git server can delay them.
- Deep pages of history use
OFFSET; filter by workflow or status instead of paging to page 1,000. - The host catalogue is filtered in memory; very large estates will need an indexed host table.
- All runners share one Kubernetes ServiceAccount and one Vault reader role.