Docs / Running yasp

High availability

yasp runs as one active instance plus any number of standbys sharing one Postgres database. A status page should stay up when the things it reports on are down, so plan for it to live outside their failure domain: another region, provider or cluster.

# How it works

  • Every instance serves HTTP: status pages, the dashboard, both APIs, SCIM, the probe API and heartbeats. Every write goes straight to the shared database, so it doesn't matter which instance a request reaches.
  • One instance holds the leader lease (a row in leader_lease). Only the leader runs the background work: the state engine, maintenance and override timers, auto-incidents, notification delivery, escalations, retention, the built-in probe and ACME certificate issuance.
  • The leader renews the lease every 10 seconds. A lease lasts 30 seconds, and a leader that can't renew steps down after 20, so two leaders never overlap. A standby takes over within about 30 seconds of losing the leader, and immediately when the leader shuts down cleanly (it releases the lease).
  • The engine reads check results from the database by cursor, so results uploaded to a standby still count, and nothing is lost in a failover. Notifications are queued in the database (the outbox): a new leader carries on from where the old one stopped. Delivery is at-least-once, so a crash mid-send can repeat a message.
  • Sessions, API tokens, certificates and settings live in the database too: signed-in users stay signed in and custom domains keep their certificates across a failover.

What isn't shared: request rate limits are per instance (so the effective limit is that many times higher), and in-memory caches warm up again on the new leader.

# Setting it up

  1. Database. Use Postgres 15 or newer with its own HA: a managed service (RDS/Aurora, Cloud SQL, Azure Flexible Server, Crunchy Bridge…) or Patroni/CloudNativePG. SQLite is single-node only: run one instance and use backups (below) for recovery.
  2. Instances. Run two or more yasp serve processes with the same yasp.toml, in particular the same database.url and the same encryption.keys. A wrong key is refused at startup.
  3. Load balancer. Send traffic to all instances. Health-check GET /readyz: it answers 200 while the instance can reach the database, with "leader": true|false in the body. Don't route only to the leader; standbys serve everything.
  4. Probes. Point remote probes at the load balancer's address. They long-poll for assignments and upload results to whichever instance they reach.
  5. HTTPS. Either terminate TLS at the load balancer, or let each instance serve it ([tls]): ACME certificates are issued by the leader and loaded by every instance from the database within a minute. With ACME, the load balancer must pass port 80 (/.well-known/acme-challenge/) to any instance; they all answer challenges from the database.
  6. Monitoring yasp itself. Set self_monitor.heartbeat_url to an external dead-man's switch (healthchecks.io, Cronitor, Better Stack…): only the leader pings it, so it alerts when no instance is leading. Alert on yasp_leader from /metrics summing to 0 across instances, too.

# Upgrades

Migrations run at startup under a database lock, so instances can be restarted one at a time. Upgrade the standbys first, then the leader; the new version must be able to read the old schema for the few seconds both run. Release notes call out any release where that isn't the case.

Back up before upgrading (below). There are no down-migrations: rolling back means restoring the backup and starting the old version.

# Backups and recovery

CommandNotes
Postgresyasp backup yasp.dump (wraps pg_dump -Fc, so it needs the PostgreSQL client tools, which the image doesn't include), or your provider's snapshots and point-in-time recoveryPITR gives the best recovery point
SQLiteyasp backup yasp-backup.db (online VACUUM INTO), or Litestream for continuous replicationCopying the file while yasp runs isn't safe
Eitheryasp config export > config.jsonMonitors, components, pages, templates and channels as reviewable JSON, without secrets

Backups don't contain the encryption key. Store encryption.keys separately (a secrets manager); without it, stored secrets (SMTP password, webhook secrets, private keys) can't be decrypted.

Restore with yasp restore <file> --yes while every instance is stopped.

# Recovery objectives

With managed Postgres and two instances in different zones: losing an instance costs at most about 30 seconds of background work (status changes and notifications are delayed, not lost), and pages and the API keep serving throughout. Losing the database is bounded by its own failover and recovery point.