Getting started
Walkthrough
A service from registration to failover.
This walkthrough uses the three-node Compose cluster from
Quick start, where your .env token has full access. Node
APIs are on ports 8081, 8082 and 8083.
export ATLAS_TOKEN=$(grep -E '^ATLAS_TOKEN=' .env | cut -d= -f2-)
auth=(-H "Authorization: Bearer $ATLAS_TOKEN" -H "Content-Type: application/json")
1. Watch the registry from node 2 (in a second terminal). Writes to any node show up here as they replicate:
curl -sN "${auth[@]}" "http://127.0.0.1:8082/v1/events?kinds=service"
2. Register a service on node 1 with a 15-second heartbeat TTL. Run the
command twice: the first call returns 201 Created, and the retry returns
200 with the same id and revision: 1, because the idempotency key
identifies the record:
curl -si "${auth[@]}" -H 'Idempotency-Key: payments-host-7' \
-d '{"name":"payments","address":"10.0.0.7:8443","version":"2.3.1","tags":["primary"],"ttl_seconds":15}' \
http://127.0.0.1:8081/v1/services
ID=<id from the response>
3. Send a heartbeat. The service turns healthy, and the watcher prints
service.registered followed by service.health:
curl -s "${auth[@]}" -X POST http://127.0.0.1:8081/v1/services/$ID/heartbeat
4. Look it up from node 3. Every node holds a replica, so any of them can answer:
curl -s "${auth[@]}" "http://127.0.0.1:8083/v1/lookup/payments?tag=primary"
5. Update it through any node. The service is owned by node 1, but you
can send the change to node 2. Node 2 forwards it to node 1 and returns the
result, so the response still shows "node_id":"atlas-1":
curl -s "${auth[@]}" -X PATCH -d '{"version":"2.4.0"}' http://127.0.0.1:8082/v1/services/$ID
If-Match guards against overwriting someone else's change. The first call
succeeds and moves the revision forward; repeating it with the old revision
fails, through any node:
curl -s "${auth[@]}" -X PATCH -H 'If-Match: "3"' -d '{"version":"2.5.0"}' http://127.0.0.1:8083/v1/services/$ID
curl -s "${auth[@]}" -X PATCH -H 'If-Match: "3"' -d '{"version":"2.6.0"}' http://127.0.0.1:8083/v1/services/$ID
# {"error":"service revision does not match If-Match","code":"precondition_failed",...}
Drain it before a deploy. Lookups skip it right away (the watcher prints
service.updated), while it stays registered and healthy:
docker compose exec atlas-1 atlas-cli drain $ID --token "$ATLAS_TOKEN"
curl -s "${auth[@]}" "http://127.0.0.1:8083/v1/lookup/payments" # no_healthy_instance
docker compose exec atlas-1 atlas-cli undrain $ID --token "$ATLAS_TOKEN"
6. Let the process "crash." Stop sending heartbeats. About 15 seconds
later the watcher prints service.health (now unhealthy), and lookups stop
returning it. After 45 seconds it prints service.deregistered.
7. Lose a whole node. Register something on node 3, then stop that node:
curl -s "${auth[@]}" -d '{"id":"search-1","name":"search","address":"10.0.0.9:9200"}' http://127.0.0.1:8083/v1/services
docker compose stop atlas-3
Its services are still listed, because nothing has deleted them yet. Clean them up in any of these ways:
- Wait
ATLAS_ORPHAN_SERVICE_REAP(10 minutes); the cluster deletes them. - Delete one from any live node:
curl -X DELETE ... :8081/v1/services/search-1. - Evict the node and everything it owned:
docker compose exec atlas-1 atlas-cli evict atlas-3 --token "$ATLAS_TOKEN".
When the node returns (docker compose start atlas-3), it rejoins through
gossip. If its services were already deleted, registering search-1 again
from any node creates a fresh record with that ID.
The same flow works from the Python and Go clients, which
handle idempotency keys, If-Match, paging and event resumption for you.