Skip to main content

Lattice Architecture

This document provides a technical deep-dive into Station Lattice’s architecture, including message flows, NATS subjects, and internal components.

System Components

Core Components

Client (internal/lattice/client.go)

The NATS connection wrapper that handles:
  • Connection lifecycle management
  • Automatic reconnection with backoff
  • TLS and NKey authentication
  • Subscription management

Registry (internal/lattice/registry.go)

JetStream KV-backed registry for stations and agents:

Presence (internal/lattice/presence.go)

Heartbeat system for station health monitoring:

Router (internal/lattice/router.go)

Capability-based agent routing:

Invoker (internal/lattice/invoker.go)

Remote agent invocation via request-reply:

Work Store (internal/lattice/work/store.go)

JetStream-backed async work tracking:

NATS Subject Conventions

Core Subjects

Request-Reply Subjects

Work Queue Subjects

Message Flows

Station Registration

Synchronous Invocation

Async Work Assignment

State Machines

Station Lifecycle

Work Item Lifecycle

JetStream Configuration

Streams

KV Buckets

Error Handling

Retry Policies

Error Types

Performance Considerations

Scaling Limits

Optimization Tips

  1. Use capability routing instead of direct station targeting when possible
  2. Batch heartbeats if running many stations on same host
  3. Set appropriate timeouts - don’t use default 60s for fast operations
  4. Monitor JetStream storage - purge old work items regularly
  5. Use async invocation for long-running tasks (>5s)