Skip to main content
Temporal Server is designed to scale horizontally across multiple dimensions. This guide covers scaling strategies and performance tuning.

Architecture for Scaling

Temporal consists of four independently scalable services:
  • Frontend - API gateway, request routing
  • History - Workflow state management, sharded by workflow ID
  • Matching - Task queue management, poll handling
  • Worker - System workflows (archival, replication, etc.)

Horizontal Scaling

Frontend Service

Scale based on API request rate:
Scaling Triggers:
  • service_requests{service_role="frontend"} rate
  • service_latency{service_role="frontend"} p99 > target
  • service_pending_requests{service_role="frontend"} > threshold
Recommended Ratio: 1 frontend per 1000-2000 RPS

History Service

The most resource-intensive service. Scale based on shard count and load:
Shard Distribution:
  • Each history node owns a subset of shards
  • Shards are distributed via consistent hashing
  • Minimum: 1 history node
  • Recommended: Number of nodes ≤ numHistoryShards / 4
Scaling Triggers:
  • ShardController latency
  • UpdateWorkflowExecution latency
  • CPU utilization > 70%
  • Memory utilization > 80%
Example for 1000 shards:

Matching Service

Scale based on task queue throughput:
Scaling Triggers:
  • PollWorkflowTaskQueue latency
  • PollActivityTaskQueue latency
  • Task dispatch latency
  • Number of unique task queues
Recommended Ratio: 1 matching node per 5000 task queues or 10000 tasks/sec

Worker Service

Scale based on system workflow load:
Scaling Triggers:
  • Archival backlog
  • Replication lag (multi-cluster)
  • System workflow queue size

Vertical Scaling

CPU Resources

History Service:
  • Minimum: 4 cores
  • Recommended: 8-16 cores
  • High throughput: 32+ cores
Other Services:
  • Minimum: 2 cores
  • Recommended: 4-8 cores

Memory Resources

History Service:
Frontend Service:
  • Minimum: 2 GB
  • Recommended: 4-8 GB
Matching Service:
  • Minimum: 2 GB
  • Recommended: 4-8 GB
  • Add 10 MB per 1000 active task queues

Persistence Layer Scaling

Cassandra

Recommended Configuration:
Scaling Guidelines:
  • 3-5 node minimum for production
  • Replication factor: 3
  • Add nodes when CPU > 70% or disk > 70%
  • Use separate clusters for default and visibility stores

PostgreSQL/MySQL

Connection Pool Configuration:
Connection Pool Sizing:
Scaling Options:
  1. Vertical scaling (increase instance size)
  2. Read replicas (not recommended for Temporal)
  3. Sharding (Vitess for MySQL)
Vitess Configuration:

Elasticsearch (Visibility)

Recommended Configuration:
Index Sharding:
  • Start with 5 shards
  • Increase to 10-20 for > 100M workflows
  • 1 replica minimum for production
Scaling Triggers:
  • Query latency > 1s p99
  • Index rate > 10000/sec
  • Disk usage > 85%

Dynamic Configuration

Tune performance without server restart:

Dynamic Config Polling

Caching Configuration

History Cache

Cache workflow execution state:
Sizing:

Events Cache

Cache workflow history events:

Workflow Limits

Enforce limits to prevent resource exhaustion:

Network Optimization

gRPC Keep-Alive

Connection Limits

Monitoring for Scaling

Key Metrics

Throughput:
Latency:
Resource Utilization:

Scaling Decision Matrix

Performance Best Practices

1. Shard Count Planning

Choose shard count at deployment time:
Note: Cannot change shard count after deployment.

2. Task Queue Design

  • Use fewer, busier task queues vs. many idle queues
  • Limit to < 10,000 unique task queues per cluster
  • Use task queue routing for versioning

3. History Growth

  • Use Continue-As-New for long-running workflows
  • Keep workflow histories < 50KB when possible
  • Monitor history_size and history_count metrics

4. Namespace Organization

  • Separate high and low priority workloads
  • Use namespaces for isolation and rate limiting
  • Monitor per-namespace metrics

5. Batch Operations

  • Use batch API operations where available
  • Reduce individual RPC calls
  • Bundle signal sends when possible

6. Client Connection Pooling

In SDK clients:

Load Testing

Benchmarking Setup

  1. Start with baseline load
  2. Gradually increase by 20% every 30 minutes
  3. Monitor all metrics
  4. Identify bottlenecks
  5. Scale and repeat

Test Scenarios

Scenario 1: High Throughput
  • Metric: Workflow starts/sec
  • Target: Saturate frontend/history
Scenario 2: High Active Workflows
  • Metric: Concurrent workflow executions
  • Target: Saturate history service memory
Scenario 3: High Task Dispatch
  • Metric: Task polls/sec
  • Target: Saturate matching service
Scenario 4: Large Workflows
  • Metric: History size
  • Target: Test persistence limits

Troubleshooting Performance

High Latency

  1. Check persistence latency
  2. Review cache hit rates
  3. Verify network connectivity
  4. Check for lock contention

Memory Issues

  1. Reduce cache sizes
  2. Decrease workflow retention
  3. Add more history nodes
  4. Review workflow history sizes

CPU Saturation

  1. Add service instances
  2. Optimize workflow code
  3. Reduce task processing frequency
  4. Check for inefficient queries

See Also