This page explains how Alf decides which servers a service runs on, what makes it move, and what doesn't. You choose a service's regions under Scaling: it runs one instance in each. See Choosing regions for how.
A server is a candidate for a new instance when all of these are true:
Among the candidates, Alf goes down this list until one server is left:
Steps 2 and 3 swap places depending on the regions:
A service can say how many instances each region runs: two in Europe, where most visitors are, and one in the US (region_instances in the API, as in alf.toml). Picking regions under Scaling is one in each; the service's instances are the sum.
| What happens | What moves |
|---|---|
| You create a service | It's placed by the rules above. If no server it may use has room, creating it is refused and nothing is made. |
| You raise its instances | New instances are added by the rules above; the ones running stay. If every server it could still go to is full, the change is refused. If there are fewer servers than instances, it runs on all of them and takes the next one that joins. |
| You pick fewer regions | The instances in the regions you took away stop; the others stay. |
| You change its regions | Instances outside the new regions move into them. If a region you added has none of its instances and another region has two, one moves over. Otherwise nothing moves. |
| You set it back to Anywhere | Nothing moves. |
| Its server goes offline | After about a minute without a report, each lost instance is replaced, in the same region if a server there can take it (a full one stands in if needed), else in another of its regions. If nothing can take it, it stays on its server and starts again when that's back. |
| That server comes back | Nothing moves back. The server drops the copies it no longer runs. |
| A server is full | It takes nothing new, and what runs on it keeps running. It may stand in for an instance lost elsewhere: that's what the room it keeps is for. |
| No server in its regions can take it | It runs on fewer servers than it wants, or, with none, shows No server yet. It gets one by itself as soon as one can take it. |
| A server joins | Nothing moves. Services that are short of servers, or have none, take it if it suits them. |
| The operators retire a server | Everything on it moves to the closest server with room that it may use (in its regions, if it's kept to some), before the server goes. A service without a volume moves at once; one with a volume, a database or a computer moves with its data: stopped for the copy, started there, and you're told. Nothing new goes to a server that's being retired. |
| The operators move a server to another region | Services kept to its old region leave it. Others stay. |
| The operators rename or merge a region | Services kept to it are kept to the new one, and stay where they are. |
| Traffic rises | Replicas start more containers on the servers it's already on. When those are full, another server in the same region runs it too until the load is gone. Load never adds regions. |
| It sleeps, wakes or is deployed | It stays on the same servers. |
A service with a volume keeps its data on one server's disk, so it runs on one server and stays there. That includes databases and computers.
alf move shop/db Europe: 1. It's stopped, so nothing is written while its data is copied. 2. Each volume is snapshotted, with a copy off the server; for a computer, everything installed in it too. 3. It's put on the new server, and its data is put back there. 4. It starts, and the old server deletes the volume it left.It's down for as long as that takes: a few minutes for a small volume, longer for a big one. The service's page shows each step. If something goes wrong before it runs on the new server, it stays where it was and runs again there.
With several instances, a visitor's request goes to the nearest instance that's awake. A sleeping instance that's much closer (more than about 1,500 km nearer) is woken instead. If the first one doesn't answer, the next nearest is tried.
Europe and the US, one instance. It runs on one server, in Europe or the US: near the project's other services, else on the least busy server. If that server goes offline, it moves to another server in the same region. It moves to the other region only when no server in its own can take it.
Europe and the US, two instances. One runs in Europe and one in the US. If the European server goes offline, the replacement goes to another European server, even when the US has an emptier one.
Europe and the US, two instances, then only Europe. The US instance leaves, and a second European server takes it. With only one server in Europe, it runs there once and takes the next European server that joins.
Anywhere, two instances. It runs on two servers near the project's other services, in different countries when that's possible. A third region added later changes nothing.