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
Architecture
Lasso useslibcluster 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: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
- Multiple A records: DNS query must return all node IPs
- Internal network: Nodes must reach each other on EPMD port (4369) and distribution ports
- 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:VM/Bare Metal with Consul
1
Register nodes with Consul
2
Configure Lasso nodes
Node Identity
Each node requires a uniqueLASSO_NODE_ID. Convention: use geographic region names for geo-distributed deployments.
Recommended Naming
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
TheLasso.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/4to all connected nodes
Topology Events
The topology module broadcasts events via Phoenix PubSub on thecluster: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:
- 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:- Network partitions
- High CPU/memory usage preventing health check responses
- Firewall blocking distribution ports
Best Practices
- Use stable node IDs: Don’t change
LASSO_NODE_IDafter deployment - Monitor cluster health: Watch for nodes in
:unresponsivestate - Plan for network partitions: Nodes gracefully degrade to standalone mode
- Use internal DNS: Don’t expose Erlang distribution to public internet
- Test failover: Verify dashboard still works when nodes disconnect
Next Steps
- Geo-Distributed Deployment - Multi-region architecture
- Production Checklist - Pre-launch verification
- Architecture - Understand cluster design