Skip to content

Using Atlas

Service registry

Register, update, look up and watch services.

All /v1/* endpoints require a bearer credential. Reads need the read scope, registry changes need write, and /v1/admin/* needs admin, which also grants the other two. Scoped credentials have a required RFC3339 expires_at, and expired credentials are rejected. The compatibility ATLAS_API_TOKENS setting grants unexpiring admin credentials, so use ATLAS_API_CREDENTIALS for least privilege. The full reference is api/v1/openapi.yaml.

Operators can create and revoke runtime credentials from the console or the admin API. Their bearer tokens are shown only once; nodes persist and replicate only SHA-256 digests and metadata over authenticated TCP anti-entropy. Static environment credentials remain operator-managed and cannot be revoked through the API. All cluster nodes must run a version supporting managed credentials; changes converge asynchronously. Admin credential changes, backups, and node evictions are recorded in a node-local audit log retained for 90 days; the console can export the retained entries as JSON.

Each node persists its registrations in SQLite and replicates them to every other node over gossip, so any node can answer reads. A registration belongs to the node that accepted it: that node runs its health checks and applies its updates. You can still send any write to any node. Every node gossips its API address (ATLAS_API_ADVERTISE_ADDR, derived automatically when unset), so a node that receives an update, heartbeat or delete for another node's service forwards it to the owner with your own credential and returns the owner's answer. The owner checks the credential again, so forwarding grants nothing extra. If the owner is alive but not answering, the response is 502 owner_unreachable; if it runs an older version without an API address, 409 not_owner with an owner_node field.

Method and pathPurpose
POST /v1/servicesRegister an instance: name, address, and optionally id, version, tags, plus either health_check or ttl_seconds. Send an Idempotency-Key header or a stable id to make retries safe.
GET /v1/servicesList instances, 100 per page by default (limit up to 1000). Filter by name, region, health, version, node_id, and repeated tag. Follow next_cursor for more.
GET /v1/services/{id}Read an instance. The ETag header is its revision.
PUT /v1/services/{id}Create or fully replace an instance with that ID.
PATCH /v1/services/{id}Change some fields, for example {"draining": true}. Send If-Match: "<revision>" to reject the change if someone else updated it first (412 precondition_failed).
POST /v1/services/{id}/heartbeatKeep a TTL instance healthy.
DELETE /v1/services/{id}Deregister.
GET /v1/lookup/{name}Select one instance by routing rules (region, key, tag, and the per-request stale, latency and tolerance overrides).
GET /v1/services/{id}/historyEvery recorded change to one service, newest first, even after it was deregistered.
GET /v1/history?name=Recent changes across services, or for one service name.
GET /v1/node, GET /v1/membersThis node, and the cluster as this node sees it.
GET /v1/eventsMembership and registry events as Server-Sent Events, resumable with Last-Event-ID.
GET /v1/admin/credentialsList configured and runtime-managed credentials by fingerprint, scopes and expiry, never the secrets.
POST /v1/admin/credentialsCreate an expiring runtime-managed credential; its token is returned once.
DELETE /v1/admin/credentials/{id}Permanently revoke a runtime-managed credential.
GET /v1/admin/auditPage through the node-local admin audit log, retained for 90 days.
POST /v1/admin/backupDownload a consistent SQLite snapshot of this node's registry.
DELETE /v1/admin/nodes/{id}Evict a failed node and delete its services.

Service lifecycle. A service is kept honest in one of two ways:

  • Health check: the owner probes health_check on the service address. The URL scheme picks the probe:

    SchemePasses when
    http://, https://the response is 2xx (redirects are not followed)
    tcp://a TCP connection opens
    grpc://, grpcs://the standard grpc.health.v1 check answers SERVING; an optional path names the gRPC service, as in grpc://10.0.0.8:9000/payments.v1.API

    The first result decides the health of a new service. After that, a slow response doesn't flap it: it turns unhealthy only after unhealthy_threshold consecutive failures (default 3) and recovers after healthy_threshold consecutive passes (default 2). check_interval_seconds overrides ATLAS_HEALTH_CHECK_INTERVAL for one service.

  • TTL: with ttl_seconds, the service calls the heartbeat endpoint itself. After one missed TTL period it is marked unhealthy; after three it is removed, and the next heartbeat returns 404, telling the client to register again.

Draining. Set "draining": true (with PATCH, or atlas-cli drain ID) before stopping an instance for a deploy. It stays registered and keeps its health, but lookups, DNS and the client load balancers stop sending it new traffic. Set it back to false, or deregister the instance once it has stopped.

If the owning node itself disappears:

  • Any node accepts a DELETE for its services.
  • The lowest-ID live node deletes them on its own after ATLAS_ORPHAN_SERVICE_REAP (10 minutes by default).
  • An admin can act at once with DELETE /v1/admin/nodes/{id}.

A registration that reuses the ID of a departed node's service moves it to the new node.

Errors. Every error response is JSON with a stable code, a readable message and the request_id that appears in the access log:

{"error":"service revision does not match If-Match","code":"precondition_failed","request_id":"3aca60719acee38e"}

Branch on code: not_found, not_owner, owner_alive, owner_unreachable, precondition_failed, no_ttl, validation_failed, invalid_json, unauthorized, insufficient_scope, rate_limited, no_healthy_instance, and the others listed in the OpenAPI Error schema.

Events. GET /v1/events streams:

  • membership events: join, update, reap
  • registry events: service.registered, service.updated, service.health, service.deregistered

Filter with kinds=member,service and service=<name>. Every event has an id: line. A client that reconnects with Last-Event-ID receives what it missed from the node's recent backlog. If the gap can't be filled, it gets event: reset and should re-read current state.

To watch this stream in a browser, use the Atlas Console. Nodes no longer embed a dashboard. With ATLAS_CONSOLE_URL set, / and /dashboard on a node redirect to the console.

GET /v1/lookup/{name}?region=...&key=... selects a healthy instance, preferring the requested region:

  • Unknown-health instances are used only when no healthy instance exists.
  • Traffic weight is applied after health, stale-owner, region and latency filtering. With a key, weighted rendezvous hashing keeps each key stable; without one, weighted round-robin distributes requests by relative weight. Weights are integers from 1 to 1000 (default 1). For a 5% canary, set each canary instance to weight 5 and each stable instance to weight 95; when running multiple instances per version, keep the version-level total ratio in mind. Unhealthy and draining instances are excluded before weighting.
  • Unhealthy and draining instances are never returned.

Routing policies. Two policies, set per node and overridable per lookup, decide the rest:

PolicySetting / queryValues
Stale records: instances whose owning node isn't alive (their process may be gone, but the record lives until the owner returns or is reaped)ATLAS_ROUTING_STALE_POLICY / ?stale=prefer-live (default): use them only when no live-owner instance exists. exclude: never. include: treat them like any other.
Latency: measured round-trip time to each owning nodeATLAS_ROUTING_LATENCY / ?latency=nearest (default): only the nearest nodes. off: ignore latency.
Latency toleranceATLAS_ROUTING_LATENCY_TOLERANCE / ?tolerance=Nodes within this duration of the nearest count as equally near, so load spreads across them (default 5ms, which absorbs probe jitter between nodes on one network; 0s routes strictly to the single nearest).

A node's own instances always count as nearest. DNS answers follow the same stale-record policy.

Metadata. Besides tags, an instance can carry key/value metadata, such as the owning team, protocol or git commit:

{"name": "payments", "address": "10.0.0.7:8443", "metadata": {"team": "payments", "protocol": "grpc"}}

Listings and lookups filter on it with meta=key:value, repeatable, and an instance must match every entry: for example GET /v1/lookup/payments?meta=protocol:grpc. Metadata replicates with the record. A PATCH replaces the whole map, like tags, and {} removes it.

  • Limits: at most 16 entries, with keys and values totalling 512 bytes.
  • Keys: letters, digits, ., _, - and /.
  • Values: at most 256 bytes.

The limits keep a record small enough to travel in ordinary gossip packets.

Webhooks. For systems that can't keep an event stream open, a node can POST events to an HTTP endpoint (admin scope):

curl -X POST -H "Authorization: Bearer $ATLAS_TOKEN" -H "Content-Type: application/json" \
  -d '{"url":"https://hooks.example.com/atlas","kinds":["service"],"service":"payments"}' \
  http://127.0.0.1:8081/v1/admin/webhooks

The response includes a signing secret, shown only once. Each delivery is the same JSON as an /v1/events event, with these headers:

  • X-Atlas-Event: the event type;
  • X-Atlas-Delivery: a unique delivery ID;
  • X-Atlas-Timestamp: Unix seconds;
  • X-Atlas-Signature: sha256= and the hex HMAC-SHA256, keyed with the secret, of <timestamp>.<body>.

Verify the signature and reject old timestamps. The Go client's atlas.VerifyWebhook does both.

Delivery behaviour:

  • Retries: network errors, 5xx, 408 and 429 responses are retried with exponential backoff, up to 8 attempts. Other responses fail the delivery straight away.
  • Order: each webhook receives events in order. A slow endpoint never delays other webhooks or the event stream.
  • Safety: redirects are not followed, and link-local addresses such as cloud metadata endpoints are refused, even through DNS.
  • Ownership: a webhook belongs to the node it was created on, which is the only node that delivers it, so each event arrives once. For redundancy, register the same endpoint on two nodes and deduplicate on the service id and revision.

GET /v1/admin/webhooks shows delivery counters, POST /v1/admin/webhooks/{id}/test sends a test event, and the console's Node admin page manages them.

History. Every node records each committed change to a service (registered, updated, health, deregistered) with the record as it was afterwards. That includes changes learned from peers, and history survives deregistration. It keeps up to 100 entries per service for ATLAS_HISTORY_RETENTION (7 days by default). Answer "what changed before the outage?" with GET /v1/services/{id}/history, or GET /v1/history?name=payments across a whole service. A node that merged several revisions at once records only the latest, so history can differ slightly between nodes.

gRPC. The typed atlas.registry.v1.RegistryService in api/v1/registry_service.proto mirrors the HTTP API, including a streaming Watch. It's served on ATLAS_GRPC_ADDR with the same credentials and scopes. Generated Go stubs are checked in as package github.com/manziosee/atlas/api/v1 (make proto regenerates them). Generate clients for other languages from the same file. The older Struct-based atlas.v1.Registry service (api/v1/registry.proto) still works for existing callers.

conn, _ := grpc.NewClient("atlas:8082", grpc.WithTransportCredentials(creds))
registry := atlasv1.NewRegistryServiceClient(conn)
ctx = metadata.AppendToOutgoingContext(ctx, "authorization", "Bearer "+token)
resp, err := registry.RegisterService(ctx, &atlasv1.RegisterServiceRequest{
	IdempotencyKey: "orders-" + hostname,
	Spec: &atlasv1.ServiceSpec{Name: "orders", Address: "10.0.0.8:8080", TtlSeconds: 15},
})

CLI. The main commands:

  • atlas-cli services --tag primary --output json lists every page.
  • atlas-cli lookup NAME --key customer-17 selects an instance.
  • atlas-cli watch --kinds service --service payments streams events.
  • atlas-cli heartbeat ID, atlas-cli drain ID, atlas-cli undrain ID and atlas-cli deregister ID manage one instance.

Admin commands:

  • atlas-cli credentials lists credentials.
  • atlas-cli backup -output node.db downloads a node's registry snapshot.
  • atlas-cli evict NODE removes a failed node and its services.
Improve this pageSource: README.md