Skip to main content
Clustering connects multiple Lasso nodes using Erlang distribution for unified observability. Each node operates independently for routing, but shares metrics and health data across the cluster.

Overview

What Clustering Provides

  • Dashboard aggregation: View metrics across all nodes in a single interface
  • Per-region drill-down: Compare provider performance by geographic region
  • Cluster health monitoring: Node status, region discovery, and topology visualization
  • Circuit breaker visibility: See breaker states across all nodes and regions

What Clustering Does NOT Affect

  • Routing decisions: Each node routes independently based on local latency
  • Request hot path: No cross-node coordination during request handling
  • Circuit breakers: Per-node state, no shared breaker coordination
  • Provider selection: Based on local measurements only
Clustering is purely for observability. A single node works standalone without clustering.

Architecture

Lasso uses libcluster with DNS-based node discovery:

Configuration

Required Environment Variables

Both variables must be set for clustering to activate: If either CLUSTER_DNS_QUERY or CLUSTER_NODE_BASENAME is missing, the node runs standalone.

Configuration in runtime.exs

The clustering configuration is loaded from environment variables:
Nodes poll the DNS name every 5 seconds and automatically join the cluster.

DNS Service Discovery

Clustering requires a DNS name that resolves to all node IPs. This is typically provided by:
  • Kubernetes: Headless service (returns all pod IPs)
  • Consul: Service discovery with DNS interface
  • Internal DNS: Custom DNS server resolving to node IPs
  • Cloud DNS: AWS Route 53, GCP Cloud DNS, etc.

DNS Requirements

  1. Multiple A records: DNS query must return all node IPs
  2. Internal network: Nodes must reach each other on EPMD port (4369) and distribution ports
  3. TTL: Low TTL for fast node discovery (recommended: 5-30 seconds)

Port Requirements

Erlang distribution requires open ports between nodes: Configure firewall rules to allow these ports between cluster nodes.

Example Configurations

Kubernetes

1

Create a headless service

2

Configure deployment with clustering

Docker Compose

For local testing with multiple nodes:
Note: Docker Compose DNS discovery requires additional configuration. For production, use Kubernetes or a proper service discovery system.

VM/Bare Metal with Consul

1

Register nodes with Consul

2

Configure Lasso nodes

Node Identity

Each node requires a unique LASSO_NODE_ID. Convention: use geographic region names for geo-distributed deployments.

Why Node ID Matters

  • Metrics partitioning: State is keyed by {provider_id, node_id}
  • Regional comparison: Dashboard groups metrics by region
  • Circuit breaker visibility: See which regions have open breakers
  • Traffic analysis: Understand request distribution across nodes

Cluster Topology

The Lasso.Cluster.Topology module manages cluster membership:

Node States

Health Checks

  • Interval: 15 seconds
  • Timeout: 5 seconds
  • Failure threshold: 3 consecutive failures → :unresponsive
  • Method: :rpc.multicall/4 to all connected nodes

Topology Events

The topology module broadcasts events via Phoenix PubSub on the cluster:topology topic:

Dashboard Integration

The dashboard aggregates metrics from all responding nodes:

MetricsStore

LassoWeb.Dashboard.MetricsStore provides cluster-wide metrics with stale-while-revalidate caching:
Cache characteristics:
  • TTL: 15 seconds
  • RPC timeout: 5 seconds
  • Invalidation: Automatic on node connect/disconnect
  • Aggregation: Weighted averages by call volume

Regional Drill-Down

The dashboard groups metrics by node_id for regional comparison:
  • View aggregate performance across all regions
  • Drill into specific regions to identify geographic issues
  • Compare provider performance region-by-region
  • See which regions have circuit breakers open

Troubleshooting

Nodes Not Connecting

1

Verify DNS resolution

2

Check EPMD connectivity

3

Verify environment variables

4

Check firewall rules

Ensure ports 4369 (EPMD) and distribution ports are open between nodes.

Nodes Becoming Unresponsive

Check node health:
Common causes:
  • Network partitions
  • High CPU/memory usage preventing health check responses
  • Firewall blocking distribution ports

Best Practices

  1. Use stable node IDs: Don’t change LASSO_NODE_ID after deployment
  2. Monitor cluster health: Watch for nodes in :unresponsive state
  3. Plan for network partitions: Nodes gracefully degrade to standalone mode
  4. Use internal DNS: Don’t expose Erlang distribution to public internet
  5. Test failover: Verify dashboard still works when nodes disconnect

Next Steps