CTRLctrl docs

High availability

Turn on high availability (HA) and your app runs as two copies on two different nodes. Both copies take traffic. If a copy's node fails, the other copy keeps serving while CTRL starts a replacement on another node.

Turning it on#

Open your app, go to settings → ctrl ha, and flip high availability. A dialog tells you what changes, and you confirm.

CTRL starts a second copy of exactly what the app runs now, the same commit or image, on another node in the app's region. The app only counts as two copies once that copy is routed and serving. The panel then lists each copy's node and whether the proxies can reach it.

With the API:

curl -X PATCH https://api.getctrl.dev/v1/apps/$APP_ID/ha \
  -H "Authorization: Bearer $CTRL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"enabled": true}'

GET /v1/apps/:app_id returns:

  • instance_count;
  • copies: each copy's node, whether it's the app's own node, and whether the proxies reach it;
  • ha_blocked: why HA can't be turned on, or null.

When HA isn't available#

The switch is off, with the reason shown, for:

  • Apps with a volume. A volume is one disk on one node, and two copies can't share it.
  • Apps with a managed database. The database is reachable only from the app's own node, so a copy elsewhere couldn't use it.
  • Previews and staging apps. They always run one copy.
  • An app that isn't running. Start it first.
  • Both copies together are bigger than all your blocks. See How it counts.

Turning it on can still fail when you confirm: if no other node in the app's region has room for a second copy, or if your apps' real use is already at your blocks. Nothing is started in that case.

How it counts#

Each copy is the app's full size, so an HA app counts twice against your blocks:

  • Allocated: an S app (½ block) with HA counts as 1 block.
  • The per-app limit: both copies together count as one app, and one app can't be bigger than all your blocks. With 1 block, an app above ½ block can't use HA.
  • Real use stays capped at your blocks in total. Your allowance on each node is split across the nodes your copies run on, so HA gives you redundancy, not extra capacity.

The resources panel takes both copies into account when you resize an HA app.

How traffic reaches the copies#

  • Both copies serve (active-active). Requests alternate between them.
  • A copy that stops answering is taken out of rotation within about 4 seconds.
  • A request that couldn't reach one copy is retried once on the other, as long as nothing had reached the app yet.
  • A copy that comes back goes back into rotation.

Because both copies take requests, write your app for that:

  • Nothing kept in memory is shared, such as sessions or caches. Keep shared state in a database or another service.
  • Scheduled jobs inside the app run twice, once in each copy.
  • There's no sticky routing. One visitor's requests can land on either copy.

Deploys#

Every deploy goes to one copy at a time, starting with the app's own node, and each copy is serving before the next starts. That covers pushes, redeploys, rollbacks, env var changes and resizes, so one copy is always up.

If a copy fails, the deploy stops there. The error says which copy failed and which already run the new version, for example:

copy on us-2: boot failed (us-1 already runs the new version)

If the failed copy's VM went down with it, the app keeps serving from the other copy alone. To start a second copy again, turn HA off and back on.

Logs, alerts and maintenance#

  • Logs: with HA on, the log viewer has a copy picker. The API takes ?node=<node_id> on GET /v1/apps/:app_id/logs.
  • Alerts are per copy. A crash on one copy alerts you even while the other is fine, and clears when that copy recovers.
  • Node maintenance moves a copy to a node that doesn't already hold the other one. Your app keeps serving from the other copy while that happens.
  • Deleting the app stops both copies.

Turning it off#

Flip the switch off and confirm. The second copy leaves the proxies' routes and stops, and the app counts once again. From then on, if the app's node fails, the app is down until CTRL replaces it.