Docs / Survive a VM outage

Keep your app and database running when one VM dies

Many apps run on a single VM: the web app and its database side by side. It's simple, but when that VM goes down, your customers stop too. This guide moves such an app onto two VMs that take over for each other, without changing the app's code.

Test results

A simple point-of-sale (POS) app writes one transaction per second. The main VM holds the web app and the database writer and is powered off hard while transactions are running. The two VMs are in different regions.

TestGap until the second VM serves againLost transactions
Ruby 2.5 + ActiveRecord 5.2 + mysql2, data from MySQL 8, MariaDB 10.11 cluster (Singapore + Bangalore), 1 Oct 2026about 13 seconds0
Node.js, PostgreSQL 18 cluster in synchronous mode, 30 Sep 2026about 21 seconds0

When the main VM comes back it rejoins by itself, catches up on missed data, and visitors return to it without data loss. During the gap the cashier sees an error and has to retry; a transaction reported as successful is never lost.

Layout: 2 VMs per customer + 1 shared witness

VMRunsSize
A (region 1)Web app + databaseLike your current VM
B (region 2)Copy of the web app + database, always in syncSame as A
Witness (region 3)No data. Only votes, so there are never two writers.Small (1 vCPU, 1 GB)

Choose the database

Your app usesSaka cluster
MySQL 8 / MariaDB, older app (e.g. Ruby 2.5, PHP 7, Docker images based on Debian 10)MariaDB 10.11 (LTS until 2028)
MySQL 8 / MariaDB, newer appMariaDB 12.3
PostgreSQLPostgreSQL 18 (or 17)

Old MySQL client libraries (libmariadb 3.1, the default in Ruby 2.5 images) read every text value as the number 0 from MariaDB 11.4 and newer. We tested it: 10.11 is correct, 11.4, 11.8, and 12.3 are not. Older apps must use 10.11.

Steps

1. Connect the VMs to Saka

Prepare VMs A and B (and a witness if you don't have one yet), then install the Saka agent on each, including the old VM. See Getting started.

2. Create a database cluster

  1. Open Databases, press + Create database cluster, choose the engine and version from the table above.
  2. Data servers: A and B. Witness: the shared witness VM.
  3. PostgreSQL: mode Zero data loss (synchronous). MariaDB is always synchronous.

The cluster is usually ready in 1 to 5 minutes; you're told on Telegram.

3. Move the old database

  1. Stop the old app so no new transactions happen during the copy (e.g. after closing time).
  2. On the cluster page, card Move an existing database into the cluster: choose the old VM, paste the old database address as in the app's config, e.g. mysql://kasir:[email protected]:3306/kasir or postgresql://kasir:[email protected]:5432/kasir, and press Copy to cluster.
  3. Saka copies tables, indexes, views, triggers, and routines, then compares the row count of every table. Test result from MySQL 8: 100,302 rows in 30 seconds, counts identical.

4. Deploy the app on A

  1. Open Sites, Create site, App from Git, choose server A. A repo with a Dockerfile is used as is (e.g. FROM ruby:2.5); see Apps from Git.
  2. On the cluster page, card Connect app servers: install the proxy on A. It always leads to a healthy database node and the same single writer, whichever VM that is.
  3. Set the app's DATABASE_URL to the proxy address for containers (the port is shown on the card; press Show password for the password):
    Rails (mysql2)
    DATABASE_URL=mysql2://root:[email protected]:13306/kasir?ssl_mode=required
  4. Deploy, open the app, and check that the old data is there.

The app must reconnect to the database when its connection drops. Rails, Laravel, Django, and Prisma do this by themselves: the connection is checked each time it is borrowed from the pool. The test above used exactly this Rails behavior, with no extra settings.

5. Add the second location on B

  1. On the app page, card Two locations, press Add a second location and choose B. B builds the same commit with the same variables; the database proxy on B is installed automatically on the same port.
  2. Change the app domain's DNS to a CNAME pointing at the load balancer address shown on the card (e.g. lbxxxx.lb.saka.work). A bare domain (e.g. shop.com) needs a DNS provider with CNAME flattening, such as Cloudflare; or use app.shop.com.
  3. HTTPS is set up on both VMs. Every deploy, rollback, and variable change on A is applied to B too.

6. Test it yourself (recommended)

Outside busy hours, power off VM A from your cloud provider's panel. Within about 30 seconds the app opens again from B with all data. Power A back on; it rejoins by itself. You're told on Telegram at each step.

One-click DNS switch & failover drill

When an app server dies, visitors need to be pointed at the standby. In Settings, One-click DNS switch stores one Cloudflare A record with two addresses (primary and standby): one click switches, one click switches back. The Cloudflare token is limited to one zone (Zone Read and DNS Edit), stored encrypted, and never shown again.

One thing you still prepare yourself: scheduled jobs (cron) must run on only one server at a time, so in a real failover enable the scheduler on the standby following your app's runbook.

With an AI agent

Connect Saka to Claude, ChatGPT, or another AI agent (see Connect AI), add the VMs in the panel, then simply ask, e.g. "Make the POS for customer Toko Maju survive a region outage: VM toko-maju-sg as main, toko-maju-blr as backup, witness-1 as witness. Ruby 2.5 app, MySQL 8 database on the old VM toko-maju." The AI calls panduan_ha, drafts a plan, asks for your approval, then runs every step above and reports the results. Steps only you can do are still asked of you: installing the agent on new VMs, stopping the old app, and changing DNS.

Good to know

Technical details: Managed databases and Sites in two locations.