SEE SEVERAL SERVES FROM ONE HUB
Note
Preview. Serve federation is a preview feature: no flag turns it on, and its commands and the serve-hub app may change in later releases. Every serve and every CLI that uses it must run Swamp 20261129.160739.0 or later.
In this tutorial, we will run three swamp serve processes on one machine: a
hub and two members. We will join the members to the hub, watch them report in,
stop one and watch the hub notice, and then look at all of them in the serve-hub
app. Everything runs on localhost.
What we will build
hub: a serve on port 19600 with token authentication, acting as the hub namedcentral.edge-1: a serve on port 19601 that starts with noserve.yamlat all.edge-2: a serve on port 19602 that starts with an olderserve.yamlcontaining a typo, which we fix on the way.
Before we start
This tutorial assumes:
- Swamp 20261129.160739.0 or later is installed. Check with
swamp --version;swamp updateinstalls the latest release. - You have signed in with
swamp auth login. jqis installed. We use it to put each join token straight into a file.- Ports 19600, 19601 and 19602 are free.
- You can open three terminals.
Create three repositories
In the first terminal, create a folder with three Swamp repositories in it:
mkdir -p ~/federation-tutorial/hub ~/federation-tutorial/edge-1 ~/federation-tutorial/edge-2
cd ~/federation-tutorial/hub && swamp repo init
cd ~/federation-tutorial/edge-1 && swamp repo init
cd ~/federation-tutorial/edge-2 && swamp repo init
cd ~/federation-tutorial/hubMake the hub
Still in ~/federation-tutorial/hub, create .swamp/serve.yaml with this
content:
version: 2
port: 19600
dashboard: true
auth:
mode: token
admins:
- user:alice
federation:
role: hub
name: centralversion: 2 comes first: serve federation only works with version 2 of the
file. The federation block makes this serve a hub called central.
Check the file:
swamp serve check-configConfig version: 2
Auth mode: token
No usernames to resolve in this mode.
Grant files: 0 file(s) checked, no problems
Result: PASSEDMint two join tokens
Each member joins with its own single-use token, minted on the hub for the name
the member will have. Mint one for edge-1 and one for edge-2, writing each
straight into a file in the member's repository that only you can read:
(umask 077; swamp serve member token create edge-1 --json | jq -r .joinToken > ../edge-1/join-token.txt)
(umask 077; swamp serve member token create edge-2 --json | jq -r .joinToken > ../edge-2/join-token.txt)
swamp serve member token listNAME STATE EXPIRES USED
edge-1 unused 2026-11-30T01:04:37.563Z -
edge-2 unused 2026-11-30T01:04:37.734Z -Notice that both tokens are unused and expire an hour from now.
Join edge-1 from no serve.yaml
edge-1 has no serve.yaml yet. We let swamp serve hub join write one:
cd ~/federation-tutorial/edge-1
swamp serve hub join http://localhost:19600 --token-file join-token.txt✓ Wrote ~/federation-tutorial/edge-1/.swamp/serve.yaml to join http://localhost:19600 with the join token in join-token.txt.
Start (or restart) serve to join: federation is read only at startup. Then run swamp serve hub to watch the join.Look at what it wrote:
cat .swamp/serve.yamlversion: 2
federation:
hub: "http://localhost:19600"
join-token-file: "join-token.txt"Join edge-2 from an older serve.yaml
edge-2 already has a configuration file, written before version 2 existed, and
it has a typo in it. Create it:
cd ~/federation-tutorial/edge-2
printf 'port: 19602\nmax-concurent-runs: 4\n' > .swamp/serve.yamlTry to join:
swamp serve hub join http://localhost:19600 --token-file join-token.txtError: Joining a hub needs serve.yaml version 2, which would refuse max-concurent-runs (did you mean max-concurrent-runs?). Fix or remove them (swamp serve check-config lists them), then run join again.The join refuses, and nothing is written. Ask check-config what it found:
swamp serve check-configConfig version: 1
Ready for version 2: no (version 2 refuses unknown keys)
• max-concurent-runs (did you mean max-concurrent-runs?)
Auth mode: none
No usernames to resolve in this mode.
Grant files: 0 file(s) checked, no problems
Result: PASSEDNotice that the file still passes: version 1 ignores the misspelt key, so this serve has been running without the run limit we meant to give it. Fix the spelling and check again:
sed -i.bak 's/max-concurent-runs/max-concurrent-runs/' .swamp/serve.yaml
swamp serve check-configConfig version: 1
Ready for version 2: yes (swamp serve check-config --upgrade stamps it)Now join:
swamp serve hub join http://localhost:19600 --token-file join-token.txt
cat .swamp/serve.yaml✓ Moved to version 2 and updated ~/federation-tutorial/edge-2/.swamp/serve.yaml to join http://localhost:19600 with the join token in join-token.txt.
Start (or restart) serve to join: federation is read only at startup. Then run swamp serve hub to watch the join.version: 2
port: 19602
max-concurrent-runs: 4
federation:
hub: "http://localhost:19600"
join-token-file: "join-token.txt"The join moved the file to version 2 and added the federation block, keeping
our settings as they were.
Start everything
Start the hub in the first terminal:
cd ~/federation-tutorial/hub
swamp serveWait for Startup complete — /ready is now serving 200. In the second terminal,
start edge-1 on its own port:
cd ~/federation-tutorial/edge-1
swamp serve --port 19601In the third terminal, start edge-2, which takes its port from its file:
cd ~/federation-tutorial/edge-2
swamp serveIn each member's log, look for the line that ends:
Joined hub "central" as member "edge-1"Watch the members report in
Open a fourth terminal and ask edge-1 about its link to the hub:
cd ~/federation-tutorial/edge-1
swamp serve hubHub: http://localhost:19600 (central)
State: joined
Member: edge-1 bab9d00c-35c6-4151-9cad-6ef7bd480b53
Joined: 2026-11-30T00:05:01.531Z
Instances:
114b8c03-56b7-441a-ba74-5b3bd0c4290f ok, last check-in 2026-11-30T00:05:01.546ZNow ask the hub what it sees:
cd ~/federation-tutorial/hub
swamp serve member listNAME ROLE STATUS LAST SEEN INSTANCES SWAMP JOINED
central hub online 14s ago 1 20261129.213627.0-sha.b1e10d9f 2026-11-30T00:04:52.616Z
edge-1 member online 5s ago 1 20261129.213627.0-sha.b1e10d9f 2026-11-30T00:05:01.517Z
edge-2 member online 5s ago 1 20261129.213627.0-sha.b1e10d9f 2026-11-30T00:05:01.682ZYour ids, times and swamp version will differ. Notice that the hub lists itself
as well as the two members, and that every row is online.
Stop a member
Go to the third terminal and stop edge-2 with Ctrl-C. Members check in every
30 seconds, so the hub needs a little while to notice. Wait two minutes, then
list the members again:
swamp serve member listNAME ROLE STATUS LAST SEEN INSTANCES SWAMP JOINED
central hub online 9s ago 1 20261129.213627.0-sha.b1e10d9f 2026-11-30T00:04:52.616Z
edge-1 member online 28s ago 1 20261129.213627.0-sha.b1e10d9f 2026-11-30T00:05:01.517Z
edge-2 member stale 2m ago 0 20261129.213627.0-sha.b1e10d9f 2026-11-30T00:05:01.682Zedge-2 is now stale, with no live instances. Left stopped for ten minutes,
it would turn offline.
Open the serve-hub app
The hub's dashboard can show all of this in the @swamp/serve-hub app. In the
hub's repository, pull the app and enable it:
swamp extension pull @swamp/serve-hub
swamp app approve @swamp/serve-hub --yesEnabled: @swamp/serve-hub
Asks for: federation:read, data:read
This app can send anything it reads to external sites.The dashboard asks for a token. Mint one for user:alice, the admin we named in
the hub's serve.yaml, and show it:
swamp access token mint alice-token --principal user:alice
swamp access token reveal alice-token --yesToken: alice-token
alice-token.<secret>
Store this token securely — do not share it in logs or messages.Open http://localhost:19600/dashboard in a browser, paste the token and sign
in. Choose Open apps, then Serve hub. The fleet map shows central in
the middle with edge-1 beside it, and the header reads 1 online and
1 stale. Switch to Table to see the same members as rows.
Clean up
Stop the hub and edge-1 with Ctrl-C in their terminals, then remove the
tutorial folder:
rm -rf ~/federation-tutorialWhat we did
We made one serve a hub, minted a single-use token for each member, and joined two serves to it: one with no configuration file, and one whose older file we fixed and moved to version 2 on the way. We watched the hub see both members, notice when one stopped, and show the fleet in the serve-hub app.
To set up a hub and members on real hosts, see Set Up a Federation Hub and Join a Serve to a Hub. To understand why it works this way, read Serve Federation.