Skip to content

Move an application to another cluster

If you redeploy somewhere else, copy the data by hand and change the address, every step can lose writes or traffic, and none of it can be undone once you are halfway.

In Flui, a move is one operation. Flui builds the new copy beside the old one, keeps it in step, and swaps the two only when you say so, or as soon as the copy is ready if you asked for that. Until the swap, nothing on the source has changed and you can cancel the whole move.

Three kinds of move

There are three commands because each kind of move carries different risks.

You want to moveCommandWhat crosses
An applicationflui migrate appThe running copy, its volumes, and its address
A Flui-managed PostgreSQL databaseflui migrate dbThe data
An application and the database it readsflui migrate fullBoth, in one cutover

migrate app moves the application and the files it keeps. The application keeps its name and address, and its volumes are copied to the new cluster. At cutover its address is repointed there, and the old cluster keeps forwarding to the new one for a while, so nobody lands on an empty cluster (see What your users see during the cutover). A database it reads is not included: use migrate db for that, or migrate full for both.

migrate db moves only the data. When both clusters are on the Flui network, a live move copies the database privately over that network. The copy is exact and kept in step continuously, and nothing is opened to the internet. The new database keeps the same database name, user and password as the source; only its address changes.

In the other cases (the Flui network is off, or you rebuild from backups) the destination comes up with its own new address, name, user and password.

At cutover the source stops taking writes. After a private copy it stops accepting connections altogether; otherwise it is left read-only. Either way it stays like that and is not removed. migrate db does not change what your application connects to. migrate full does that for you.

The shape of every move

Every move has four steps, and only the last two are permanent.

  1. Create. The destination is built and kept in step with the source. The source keeps serving.
  2. Cut over. Traffic, writes, or both move to the destination. --cutover auto does this as soon as the destination is ready. --cutover manual pauses and waits for you.
  3. Abort. Available until the cutover passes its point of no return. The destination is removed and the source is left as it was.
  4. Destroy the source. Optional, and only after the cutover. It gives the old cluster its capacity back, and cannot be undone.

Steps 2 and 4 are separate so you can check the result first. After the cutover the old copy stays in place until you destroy it. It still uses capacity, and while the old cluster is forwarding to the new one it is still doing a job.

A restart of Flui in the middle of an application move, a full move or a private database move does not lose it. The move picks up where it was.

What can move, and what cannot

Flui refuses a move it cannot finish when you ask for it, not halfway through. The refusal says which rule you hit. A full move checks the application’s rules too, before it copies the database.

An application can move when:

  • it runs somewhere other than the target cluster;
  • it does not read values out of another application’s secrets (move the applications it depends on first);
  • it answers at a real domain. An application still on the fallback address built from its cluster’s IP cannot move, because that address belongs to the old cluster. Assign a DNS zone first: see Put an application on the internet;
  • the target cluster has that DNS zone assigned too, so the name can follow the application;
  • no other application that is staying behind answers at the same address. Give one of them its own name first;
  • if it has volumes, there is a backup destination for them to travel through: the one protecting the application, your only one, or the one you name with --backup-destination. See Protect and restore.

Only one migration can run at a time for each application.

migrate full has one more rule. Flui has to see, in the application’s own configuration, that it points at the database you named: either the standard PGHOST setting matching the source database, or a postgres:// URL that matches it. An application that reads its connection from a linked secret cannot be rewired, so the move is refused instead of guessed at. The exception is a database with a connection pooler: an application that reads FLUI_CONNECTION_URL or FLUI_DIRECT_URL from the database itself is accepted, here and under the rule about other applications’ secrets above, and Flui rewires it. In that case the application must also be the only one using the database. Move or repoint the others first; the refusal names them.

A private database move also needs the target cluster to be live on the Flui network. Flui checks this before it starts and refuses otherwise, telling you which node is missing. The network reconciles every 10 minutes, so you can wait for it and start the move again.

Start the move

Terminal window
# an application, with its volumes
flui migrate app create my-api --to production-eu
# a managed database
flui migrate db create orders-db --to production-eu
# both together
flui migrate full create my-api --db orders-db --to production-eu

--to (-t) is required and takes a cluster name or id. You can give the application and the database by name or by id. --from (-f) is optional: Flui looks for the name on every cluster, workload clusters included, and asks you for --from only when the same name is on more than one.

--cutover auto is the default on all three. Pass --cutover manual to pause the move and start the cutover yourself.

flui migrate app and flui migrate full take --backup-destination to choose where volumes travel through. flui migrate app also takes --no-bridge, which moves only the DNS record at cutover and leaves the old cluster out of it.

flui migrate db has four more flags:

FlagWhat it does
--mode live|restorelive copies from the running database, then cuts over. restore rebuilds from its backups instead, for when the source is already gone. Default live.
--at <ISO-8601>Restore mode only: the point in time to recover to.
--nameA display name for the new database. Defaults to the old one’s slug with -migrated on the end.
--no-verifySkips the per-table row-count comparison Flui makes at cutover. The check is on by default, and a mismatch stops the cutover. A private copy is exact, so it has no row count to compare.

flui migrate full has --staging, which decides how the new copy of the application waits:

  • scaled-down (the default): the copy is built but not started until cutover. This is safe, and the write pause at cutover is a little longer.
  • live-fenced: the copy is started at full size against the destination database while that database is still read-only, so it is already warm at the swap. This shortens the pause, but your application has to meet two conditions. It must start and pass its health check without writing anything, and it must not run background work with effects outside the database (queue consumers, scheduled jobs, outgoing mail or webhooks) until cutover. Flui holds back only its database writes.

When the database has a connection pooler, flui migrate full also takes --pause-deadline <seconds>. See When the database has a pooler.

Watch it

A move takes time. These are the states it goes through:

  • pending, then provisioning: the destination is being built. A full move shows db_replicating and then app_staging instead.
  • replicating: a database move is copying and keeping in step. A database restored from backups goes through restoring instead, straight to completed.
  • ready (an application or a full move) or synced (a database): the paused state. Under auto the move passes straight through it. Under manual it waits here for you.
  • cutover.
  • bridging (an application or a full move): the application is served from the destination and the old cluster still forwards to it. For traffic the move is done. It stays here until you destroy the source.
  • completed, failed, or aborted.

A full move has one more state, failed_forward: it failed after the database was promoted, which is the one point that is never rolled back. You can recover by running the cutover again.

Terminal window
flui migrate app list
flui migrate db show <migration-id>
flui migrate full list --json

Each of the three kinds has its own list and show. list prints the id, the state, the target cluster and the cutover mode. show adds what is moving and where, and the error, if there was one. Both take --json.

show for an application or a full move also prints the bridge: whether it is planned, open or closed, the names it forwards and their certificates, when the DNS record moved, and from when it can be closed. When the move goes by DNS only, it says why.

show for a database or a full move also prints:

  • Kind: physical for a private copy over the Flui network, logical otherwise;
  • Link: the state of the private link between the two clusters, and whether the two ends have reached each other;
  • Copy: how far the copy has got, and how much is still to catch up once it runs;
  • Fence: when the source stopped taking writes and when the destination was asked to take over;
  • Write pause: how long writes were paused, and what ended the pause;
  • Pooler and Cut, when the database has a connection pooler: the pooler’s pause and the clients cut at its deadline (see When the database has a pooler);
  • Next: what is left for you once the move has completed. Flui does not protect the new database with a backup policy for you, so that comes first. A database move also reminds you to point your applications at the new database, and a full move to destroy the source.

When an interrupted cutover can be resumed, show prints the command to do it.

Cut over

With --cutover auto there is nothing to do here. The move cuts over as soon as the destination is ready.

With manual, the move waits at ready (or synced for a database) until you start the cutover, so you choose when it happens.

What the cutover does depends on the kind:

  • An application is repointed at the destination cluster and its address follows it. It keeps its name and identity throughout. With the bridge, the certificate for its address is prepared on the destination before the cutover; the old cluster then starts forwarding to the new one, its own copy stops, and the DNS record moves. If the application has volumes, it stops while the last changes to its files are copied, then starts on the destination. The move tells you this when you start it, and records how long the pause lasted. If the copy fails, the application starts again on its original cluster.
  • A database stops taking writes. After a private copy, Flui waits until the destination has caught up with the last write and promotes it. Otherwise it checks the row counts table by table against the copy, unless you turned that off, and promotes the copy. From then on the source does not take writes and stays that way.
  • A full move does both together, and rewrites the application’s connection settings to the new database in the same step.
Terminal window
flui migrate app cutover <migration-id>
flui migrate db cutover <migration-id>
flui migrate full cutover <migration-id>

Use the command that matches the kind of move. You cannot drive the parts of a full move on their own. Flui refuses and tells you to drive the full move instead.

The same command resumes a cutover that was interrupted, an application cutover that failed after the bridge opened, and a full move in failed_forward.

What your users see during the cutover

Moving an application. The old cluster keeps answering at the application’s address and forwards everything to the new cluster while the DNS record moves. This is the bridge. A client that still has the old address in its DNS cache reaches the application anyway, so nobody is sent to an empty cluster.

The bridge has limits:

  • it runs on the old cluster, so it helps only while that cluster is up;
  • while it is open, requests that come through it reach the application from the old cluster’s address, not from the client’s own;
  • it is skipped, and the move goes by DNS only, when an address is a wildcard name, has DNS that Flui does not manage, has an IP allow-list, uses a shared certificate, or when the target cluster has no public IPv4 address to forward to. It is also skipped when no valid certificate is ready on the destination at cutover. The move tells you why.

Moving a database on its own. At cutover the source stops taking writes. After a private copy it refuses every connection, so an application still pointing at it loses its database until you point it at the new one.

Moving both with migrate full. Writes pause from the moment the source stops taking them until the application on the destination can write again. The move records how long that was.

With a private copy, --staging live-fenced, the bridge, and no volumes, the pause is as short as it gets. The new copy of the application is already running on the destination against the read-only copy of the database. At cutover the old cluster starts forwarding to it before writes stop, so reads keep working the whole time. Writes pause only from that moment until the destination database is promoted: a few seconds in our tests. When the database has a pooler and the application connects through it, those writes wait instead of failing; see When the database has a pooler. With any other combination the application on the old cluster cannot write during the cutover, and after a private copy it cannot reach its database at all, until traffic reaches the destination.

When the database has a pooler

A managed PostgreSQL installed from the catalog usually has a connection pooler in front of it (see Connect an application to a managed PostgreSQL). When you move it together with its application, writes are not refused at the switch. They wait in the pooler.

At cutover:

  1. The pooler is paused. New transactions wait in it.
  2. Transactions already running get a deadline to finish: 5 seconds by default.
  3. A transaction still open at the deadline is cut. Its client gets an error and must retry.
  4. The new copy of the database is promoted, and the pooler resumes against it. The waiting transactions go through.

Measured on a move with a private copy, --staging live-fenced and the bridge, writes waited 7.8 seconds with nothing in flight, and 14.3 seconds when a transaction held on until the deadline. A probe writing and reading throughout saw no failed write and no wrong read.

If Flui itself restarts during the pause, writes keep waiting until it is back (59.4 seconds in our test) and none is lost. A client with a short HTTP timeout may give up before then.

Set the deadline with --pause-deadline <seconds>, from 1 to 60, on flui migrate full create, or on flui migrate full cutover to replace it for a manual cutover. An agent passes pauseDeadlineSeconds to migrate_full or migration_cutover. The dashboard has no field for it and uses the default.

flui migrate full show prints what happened: the Write pause line, for example 7.8s (writes waited in the poolers, none failed), a Pooler line with when it paused, when it resumed and the deadline, and a Cut list with each client cut at the deadline. The dashboard row shows the clients that were cut.

What this covers, and what it does not:

  • Only clients on FLUI_CONNECTION_URL wait. A client on FLUI_DIRECT_URL talks to the database directly and sees the switch as before.
  • Zero refused writes holds in transaction mode. In session mode every client still holds its connection at the deadline, so every client is cut and must reconnect.
  • A database without a pooler moves as before. Writes are refused for a few seconds at the switch.
  • flui migrate app refuses a database with a pooler. Moving it as an application would leave the pooler behind. Use flui migrate db or flui migrate full.

Abort a move

An abort removes what was built on the destination and leaves the source as it was. Nothing has moved yet, so there is nothing to move back.

You can abort from pending up to the paused state, and also from failed, so a broken move can be cleaned up. A private database move can also be aborted during its cutover, until the destination has been asked to take over. After that it only goes forward.

Abort is no longer available once traffic has moved. An application move whose bridge is open refuses an abort and tells you to resume the cutover. For a full move the limit comes earlier: once its database has started its cutover, abort is refused. After that point there is no consistent old state to return to, so you finish the cutover instead. The refusal tells you so.

When you abort a database move, Flui closes the link between the two copies but leaves the half-built destination database in place for you to inspect. You have to remove it yourself.

Terminal window
flui migrate app abort <migration-id>
flui migrate db abort <migration-id>
flui migrate full abort <migration-id>

Each asks you to confirm. --yes (-y) skips the question.

Destroy the source

After the cutover the old copy is still there. With the bridge it forwards to the new cluster; without it, it is drained. Either way it still uses the old cluster’s capacity.

destroy-source frees that capacity. It works on a move in bridging or completed, it touches only the copy on the source cluster, and it cannot be undone. When the bridge is open, it closes the bridge first and the move becomes completed.

While the bridge is open, destroy-source is refused until twice the DNS record’s TTL has passed since the switch, because clients may still hold the old address until then. The refusal gives you the time. You can close the bridge earlier on purpose; clients that still resolve the old cluster then lose the application.

A database move has no destroy step. The source database is left as the cutover left it, not removed. To remove it, remove it as an application, which also deletes its storage. See Remove an application and its data.

Terminal window
flui migrate app destroy-source <migration-id>
flui migrate full destroy-source <migration-id>

Both ask you to confirm. --yes (-y) skips the question; use it only in scripts. --close-bridge closes an open bridge now instead of waiting.

What an agent may do with this

There are three permission groups, from lowest to highest:

GroupWhat it reaches
See migrationsmigration_list, migration_get. Changes nothing.
Run migrationsThe above, plus migrate_app, migrate_db, migrate_full and migration_cutover, and reading the applications and clusters involved.
Abort and tear down migrationsThe above, plus migration_abort and migration_destroy_source.

A group is granted or refused as a whole, so what you agreed to is exactly what the key carries. Choose what your agent may do explains how to choose one.

Every step that changes something on the destination or removes something on the source stops and asks a person. You approve it in the dashboard, and the agent finds out by trying again. When your agent stops to ask you explains why it works that way.

Where to go next