Skip to content

Using Atlas

Client libraries

Go, Python, Node.js/TypeScript and Java, plus client-side load balancing.

Python client

The client needs only the standard library and supports bearer auth, custom CA roots, optional mTLS, and the whole API, including watch streams, admin calls and an asyncio variant:

python -m pip install ./clients/python
from atlas import AtlasClient, AtlasError

client = AtlasClient("https://atlas.example:8080", token="...", ca_file="ca.crt")

# Safe to retry: the same idempotency key always maps to the same record.
me = client.register("payments", "10.0.0.7:8443", ttl_seconds=15, idempotency_key="payments-host-7")
client.heartbeat(me["id"])                       # call every ~5 s from your service
client.drain(me["id"])                           # before shutting down: stop new traffic

instance = client.lookup("payments", region="eu", key="customer-17")
print(instance["address"])

try:
    client.update(me["id"], version="2.0.0", if_revision=me["revision"])
except AtlasError as err:
    if err.code == "precondition_failed":
        ...                                      # someone changed it first; re-read and retry

for event in client.watch(kinds=["service"], service="payments"):   # reconnects and resumes
    print(event["type"], event["service"]["address"])
from atlas import AsyncAtlasClient

client = AsyncAtlasClient("https://atlas.example:8080", token="...")
instance = await client.lookup("payments")
async for event in client.watch(kinds=["member"]):
    print(event["type"], event["member"]["id"], event["member"]["state"])

client.list_services(...) returns every page, and iter_services / list_page give you control over paging. Run the tests against a node with make test-python (set ATLAS_TEST_ENDPOINT and an admin ATLAS_TEST_TOKEN); CI runs them against a freshly started node.

The CLI accepts connection defaults from ATLAS_CLI_CONFIG, a JSON file with addr, token, ca_file, client_cert, and client_key fields. Environment variables and command flags override file values. Protect the file as a secret because it may contain the bearer token; use ATLAS_TOKEN when you want the token kept outside the file.

The public Go client lives at github.com/manziosee/atlas/pkg/atlas:

client, err := atlas.NewClient("https://atlas.example", token, httpClient)
if err != nil { return err }

me, err := client.RegisterIdempotent(ctx, "payments-"+hostname, atlas.RegisterRequest{
	Name: "payments", Address: "10.0.0.7:8443", TTLSeconds: 15,
})
_, err = client.Heartbeat(ctx, me.ID)
instance, err := client.Lookup(ctx, "payments", "jnb", "customer-17")
if atlas.IsCode(err, "no_healthy_instance") { /* fall back */ }

err = client.WatchWithOptions(ctx, atlas.WatchOptions{Kinds: []string{"service"}, Reconnect: true},
	func(e atlas.Event) error { log.Println(e.Type, e.Service.Address); return nil })

List follows every page; ListPage returns one. Update, Replace, Drain, Undrain, Delete, History, RecentHistory, LookupWithOptions (routing overrides), Node, Members, Credentials, Backup and EvictNode cover the rest of the API, and *atlas.APIError carries the server's Code, RequestID and OwnerNode.

Node.js / TypeScript client

clients/node is written in TypeScript and has no runtime dependencies: it uses the fetch built into Node.js 20+. It covers the whole API, including history, routing overrides and a watch stream that resumes after disconnects.

cd clients/node && npm ci && npm run build
import { hostname } from "node:os";
import { AtlasClient, AtlasError } from "@manziosee/atlas-client";

const atlas = new AtlasClient("https://atlas.example:8080", process.env.ATLAS_TOKEN!);
const me = await atlas.register({ name: "payments", address: "10.0.0.7:8443", ttl_seconds: 15 },
  { idempotencyKey: `payments-${hostname()}` });
setInterval(() => atlas.heartbeat(me.id).catch(console.error), 5_000);

const instance = await atlas.lookup("payments", { region: "eu", stale: "exclude" });
try {
  await atlas.update(me.id, { version: "2.0.0" }, me.revision);
} catch (error) {
  if (error instanceof AtlasError && error.code === "precondition_failed") { /* re-read and retry */ }
}
for await (const event of atlas.watch({ kinds: ["service"], service: "payments" })) {
  console.log(event.type, event.service?.address);
}

To trust a private CA, set NODE_EXTRA_CA_CERTS, or pass your own fetch in the client options.

Java client

clients/java targets Java 17+, uses java.net.http and has no runtime dependencies; it includes a small JSON reader and writer.

cd clients/java && mvn -B install
AtlasClient atlas = new AtlasClient("https://atlas.example:8080", System.getenv("ATLAS_TOKEN"));
Service me = atlas.register(new ServiceSpec("payments", "10.0.0.7:8443").ttlSeconds(15),
    null, "payments-" + InetAddress.getLocalHost().getHostName());
atlas.heartbeat(me.id());

Service instance = atlas.lookup("payments", new LookupOptions().region("eu").stale("exclude"));
try {
  atlas.update(me.id(), new ServicePatch().version("2.0.0"), me.revision());
} catch (AtlasException e) {
  if (e.code().equals("precondition_failed")) { /* re-read and retry */ }
}
atlas.watch("service", "payments", null, true, event -> {
  System.out.println(event.type() + " " + event.service().address());
  return true; // false stops watching
});

For a private CA or mutual TLS, pass an HttpClient built with your SSLContext.

Client-side load balancing

Services don't have to call /v1/lookup before every request. The Go client keeps a live list of each service's routable instances: healthy (or unknown-health when none is healthy), never draining, and from your region first. It updates the list from the event stream and re-reads it every 30 seconds.

HTTP: use atlas.NewTransport as the http.Client transport and address services as <name>.atlas. Requests rotate across instances. If an instance refuses the connection, it's skipped for 30 seconds and a replayable request (GET, HEAD, OPTIONS, PUT, DELETE, or anything with an Idempotency-Key) is retried once on another instance. Other hosts pass through unchanged.

transport := atlas.NewTransport(client, nil, atlas.InstanceOptions{Region: "eu"})
defer transport.Close()
httpClient := &http.Client{Transport: transport}
resp, err := httpClient.Get("http://payments.atlas/v1/charges")

gRPC: register the resolver once, then dial atlas:///<name>, optionally with ?region= and repeated &tag= filters. The connection follows the instance list and uses round_robin unless your service config picks another policy.

import "github.com/manziosee/atlas/pkg/atlas/grpcresolver"

grpcresolver.Register(client)
conn, err := grpc.NewClient("atlas:///payments?region=eu&tag=v2", grpc.WithTransportCredentials(creds))

For finer control, client.WatchInstances returns the same live list with Instances, Pick and OnChange.

Generate command completion with atlas-cli completion bash, zsh, fish, or powershell, then load the printed script in the matching shell.

Without Docker:

make build && make test
ATLAS_GOSSIP_KEY=$(./bin/atlas-cli keygen) ATLAS_API_TOKENS=$(./bin/atlas-cli tokengen) ./bin/atlas-node

Membership scale benchmark:

make bench-scale

The in-process simulator checks full-view convergence at 100, 500, and 1,000 nodes using the production membership handlers, bounded UDP gossip, and TCP push-pull semantics over a lossless fake transport. Results include convergence-ms; CI uploads each run.

One local run on Windows/amd64 with an Intel Core i5-8350U at 1.70 GHz (2026-10-20):

NodesFull-view convergence
1001.99 s
50026.78 s
1,00075.22 s

These are single-run in-process measurements over a lossless simulated transport. They measure gossip scheduling and membership merge costs, not socket framing, AEAD CPU, network latency, packet loss, or cross-region links. The 1,000-node run reached approximately 1.2 GiB peak process memory on this host.

Improve this pageSource: README.md, README.md, README.md, README.md