Where services run

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.

The short version

Which servers it can use

A server is a candidate for a new instance when all of these are true:

Which one it picks

Among the candidates, Alf goes down this list until one server is left:

  1. The region of the instance it replaces. When an instance is lost because its server went offline, the replacement goes to that server's region.
  2. A region the service isn't in yet, so instances spread over regions.
  3. A server the project's other services already run on, so they reach each other on the same machine.
  4. A country the service isn't in yet.
  5. The server with the fewest services, then the one with the least CPU in use.

Steps 2 and 3 swap places depending on the regions:

How many in each region

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.

Every case

What happensWhat moves
You create a serviceIt'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 instancesNew 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 regionsThe instances in the regions you took away stop; the others stay.
You change its regionsInstances 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 AnywhereNothing moves.
Its server goes offlineAfter 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 backNothing moves back. The server drops the copies it no longer runs.
A server is fullIt 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 itIt 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 joinsNothing moves. Services that are short of servers, or have none, take it if it suits them.
The operators retire a serverEverything 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 regionServices kept to its old region leave it. Others stay.
The operators rename or merge a regionServices kept to it are kept to the new one, and stay where they are.
Traffic risesReplicas 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 deployedIt stays on the same servers.

Services with a volume

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.

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.

Which instance visitors reach

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.

Examples

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.