Skip to content

Internals

Design decisions

Architecture decision records.

ADR-0001: SWIM-style gossip instead of centralized consensus

  • Status: Accepted
  • Date: 2026-10-18

Context

Atlas answers "where does service X run?" for nodes spread across continents (JNB, FRA, SIN, IAD). Cross-region RTTs are 150–300 ms and links partition. Discovery must keep working in every region during a partition, and a lookup must never pay a cross-continent round trip.

Decision

Use a SWIM-inspired membership protocol with epidemic dissemination:

  • Every node keeps a full local copy of membership state. Reads are local.
  • Failure detection: each period, probe one random member and suspect it if no ack arrives. Suspects become dead after a timeout unless they refute.
  • Refutation through incarnation numbers: only the node itself can increase its incarnation, so it can always override rumors about itself.
  • Dissemination: state piggybacks on probes, plus push gossip to k random peers and periodic push-pull anti-entropy.

Consequences

  • ✅ O(1) per-node probe load, O(log n) rounds to spread an update.
  • ✅ Available under partition (AP): each side keeps serving its view.
  • ✅ No leader, no quorum, no single point of failure.
  • ⚠️ Eventually consistent: nodes briefly disagree after changes.
  • ⚠️ Application state needs conflict resolution (planned CRDTs, ADR TBD).

Alternatives considered

  • Raft/etcd/Consul servers: strong consistency, but every write (and linearizable read) crosses regions and a minority partition stops writing.
  • All-to-all heartbeats: O(n²) traffic; does not scale past tens of nodes.
  • hashicorp/memberlist: production-grade, but building the protocol is the point of this project. Its design (Lifeguard) is our reference.

ADR-0002: Authenticated encryption for all gossip (AES-256-GCM keyring)

  • Status: Accepted
  • Date: 2026-10-18

Context

Gossip crosses the public internet between regions. Unauthenticated membership traffic would let anyone declare nodes dead, inject fake nodes or map the cluster topology.

Decision

  • Seal every datagram with AES-256-GCM (AEAD): confidentiality and integrity in one primitive, hardware accelerated (AES-NI / ARMv8 CE).
  • Envelope: version(1) ‖ nonce(12, random) ‖ ciphertext ‖ tag(16).
  • AAD = atlas/gossip/v1 so ciphertexts cannot be confused with another protocol sharing the key.
  • Keyring: 1 primary (encrypt) + up to 3 secondary (decrypt-only) keys for rolling rotation without downtime.
  • Decrypt before parse: unauthenticated bytes never reach the decoder.
  • Timestamp in every message, rejected outside ATLAS_MAX_CLOCK_SKEW.

Consequences

  • ✅ Rogue hosts without the key cannot affect the cluster.
  • ✅ Rotation is three config pushes, no restart storm.
  • ⚠️ 29 bytes overhead per packet.
  • ⚠️ Random 96-bit nonces: safe for ~2³² messages per key; rotate keys periodically (we recommend quarterly, or at once if a key leaks).
  • ⚠️ Shared key = flat trust. Per-node identity is a future ADR.

Alternatives considered

  • DTLS per peer: per-node identity, but needs handshakes with n peers and state per pair, which works against gossip's connectionless model.
  • WireGuard mesh only: good where it exists (Fly.io 6PN), but leaves Atlas insecure everywhere else. We do both: defense in depth.
  • ChaCha20-Poly1305: equally strong; AES-GCM chosen for hardware acceleration on our server targets. The version byte allows switching.

ADR-0003: API authentication — TLS 1.3, bearer tokens, optional mTLS

  • Status: Accepted
  • Date: 2026-10-18

Context

The HTTP API exposes cluster topology. It must be safe by default, simple to use from the CLI and CI, and stricter in production.

Decision

  • TLS 1.3 only for the API; production refuses to start without TLS unless ATLAS_TLS_TERMINATED_UPSTREAM=true declares a trusted terminating proxy.
  • Bearer tokens (≥ 32 chars, generated by atlas-cli tokengen), stored as SHA-256 digests and compared in constant time against all tokens. A list of tokens enables rotation.
  • New deployments may instead configure ATLAS_API_CREDENTIALS as a JSON array with read, write, or admin scopes and a required RFC3339 expiry. Expired tokens are rejected and under-scoped requests receive 403. The legacy ATLAS_API_TOKENS setting remains admin-only and non-expiring for backwards compatibility.
  • Optional mTLS (ATLAS_TLS_CLIENT_AUTH=true) for zero-trust setups.
  • Certificates hot-reload from disk so short-lived certs (cert-manager, Vault) rotate without restarts.
  • Health endpoints stay unauthenticated so orchestrators can probe them; they reveal nothing beyond liveness.

Consequences

  • ✅ Credential rotation remains available through SIGHUP.
  • ✅ Scoped credentials can expire and receive read-only or write access.
  • ⚠️ Legacy static tokens remain non-expiring admin credentials until operators migrate to ATLAS_API_CREDENTIALS.

Alternatives considered

  • JWT now: needs an issuer and key distribution, which is premature.
  • mTLS only: strongest, but painful for ad-hoc CLI use; kept optional.

ADR-0004: Deterministic service record merge

  • Status: Accepted
  • Date: 2026-10-20

Context

Service records replicate asynchronously. Nodes can accept updates on separate partitions and later exchange snapshots. A merge must converge regardless of message order, preserve deletion tombstones, and avoid relying on synchronized wall clocks for every comparison.

Decision

Treat each service instance as a revisioned last-write-wins register. Compare records by the tuple (revision, updated_at, node_id, deleted, canonical record), taking the maximum. The canonical record is JSON for the stable service struct with its local-only checked_at value cleared. A missing update time from an older peer uses a deterministic revision-derived fallback.

TCP push-pull exchanges SHA-256 digests of sorted, length-framed records. On a mismatch, bounded snapshots include tombstones; the requester returns its snapshot once so records present on either side are merged. Digests exclude checked_at, because it is node-local health-check bookkeeping.

Consequences

  • Merge is idempotent and order independent for records with the same instance ID, provided all replicas use this ordering.
  • Revisions are monotonic per instance; a larger revision takes precedence.
  • Equal revisions resolve by update time, owner ID, deletion flag, and stable content ordering.
  • Health-check timestamps are not replicated state.
  • A full repair is bounded by 100,000 rows and the existing 16 MiB stream cap; oversized registries fail repair explicitly rather than silently claiming convergence.
  • This is per-instance LWW state, not an observed-remove set for service identities. Concurrent reuse of one instance ID is resolved by the tuple.
Improve this pageSource: docs/adr/0001-swim-gossip-over-consensus.md, docs/adr/0002-gossip-encryption.md, docs/adr/0003-api-authentication.md, docs/adr/0004-service-merge.md