Cluster Architecture
A production Temporal cluster typically consists of:1
Multiple Service Instances
Each Temporal service (Frontend, History, Matching, Worker) runs multiple instances across different nodes
2
Membership Protocol
Services use the Ringpop gossip protocol for cluster membership and peer discovery
3
Consistent Hashing
History shards are distributed across History service instances using consistent hashing
4
Shared Database
All instances connect to the same persistence and visibility databases
Service Roles and Scaling
Frontend Service
Stateless - Horizontal Scaling
The Frontend service is completely stateless and can be scaled horizontally.Scaling Guidelines:
- Start with 2-3 instances for HA
- Add instances based on request rate
- Each instance handles ~10k requests/sec
- Use load balancer for traffic distribution
History Service
Stateful - Shard-Based Scaling
The History service manages workflow execution state using consistent hashing of history shards.Scaling Guidelines:
- Minimum 3 instances for HA
- Shards automatically redistribute on instance changes
- Each instance handles multiple shards
- More instances = better shard distribution
Matching Service
Semi-Stateful - Queue-Based
The Matching service routes tasks to workers and maintains task queue state.Scaling Guidelines:
- Start with 2-3 instances
- Scale based on task queue throughput
- Task queues are partitioned across instances
Worker Service
Stateless - Background Operations
The Worker service executes internal system workflows like archival.Scaling Guidelines:
- Usually 1-2 instances sufficient
- Scale if system workflow backlog occurs
Cluster Membership
Temporal services use Ringpop for cluster membership and service discovery.Membership Configuration
How Membership Works
1
Service Startup
Each service instance binds to its membership port and announces itself
2
Peer Discovery
Instances discover each other through the shared database (cluster_membership table)
3
Gossip Protocol
Ringpop gossip maintains consistent view of cluster membership
4
Health Checking
Services continuously monitor peer health and detect failures
5
Shard Rebalancing
When topology changes, History shards automatically redistribute
Broadcast Address
The broadcast address is how services advertise themselves to peers:- Auto-Detection
- Explicit IP
- Environment Variable
- Simple deployments
- Kubernetes with pod DNS
- Docker with proper networking
Multi-Node Deployment Examples
Docker Compose Cluster
Kubernetes Deployment
For Kubernetes, use the official Helm charts:Example Helm Values
Example Helm Values
values.yaml
Multi-Cluster Replication
For geo-distributed deployments, Temporal supports multi-cluster replication.Cluster Configuration
- Cluster A
- Cluster B
config/cluster-a.yaml
Registering Remote Clusters
After both clusters are running:Global Namespaces
Create a namespace that replicates across clusters:Failover
Manual failover to switch active cluster:Load Balancing
Frontend Load Balancing
- Nginx
- HAProxy
- Kubernetes Service
High Availability Checklist
1
Multiple Instances
- At least 2 Frontend instances
- At least 3 History instances
- At least 2 Matching instances
- At least 1 Worker instance
2
Database HA
- Database replication configured
- Automatic failover enabled
- Regular backups scheduled
- Connection pooling tuned
3
Network Configuration
- Load balancer for Frontend service
- Health checks configured
- Network policies in place
- DNS properly configured
4
Monitoring
- Prometheus metrics collection
- Grafana dashboards
- Alerting rules configured
- Log aggregation setup
5
Resource Management
- CPU/Memory limits set
- Pod/container auto-scaling
- Disk space monitoring
- Rate limiting configured
Troubleshooting Cluster Issues
Uneven shard distribution
Uneven shard distribution
Symptoms: Some History instances have many more shards than othersSolutions:
- Restart History instances one at a time
- Wait for membership stabilization (30-60s)
- Check broadcast addresses are correct
- Verify all instances can reach the database
Service discovery failures
Service discovery failures
Symptoms: Services cannot find each otherSolutions:
- Check membership ports are accessible
- Verify broadcast addresses resolve correctly
- Check firewall rules
- Ensure database connectivity for membership table
Load balancer issues
Load balancer issues
Symptoms: Connection failures, timeouts, uneven loadSolutions:
- Configure health checks properly
- Use least-connections algorithm
- Set appropriate timeouts (5s connect, 300s idle)
- Monitor backend health status
Performance Optimization
Shard Count Guidelines
- Small Scale
- Medium Scale
- Large Scale
Resource Recommendations
These are starting points. Monitor actual usage and adjust based on workload patterns.