Overview
Temporal automatically retries failed activities and child workflows according to configurable retry policies:- Exponential backoff - Increasing delays between retry attempts
- Maximum attempts - Limit total retry count
- Timeout controls - Cap retry duration
- Non-retriable errors - Fail immediately for specific error types
- Backoff coefficient - Control retry delay growth rate
Retry policies are core to Temporal’s reliability guarantees. Configure them carefully to balance fault tolerance with resource usage.
Retry Policy Configuration
Delay before the first retry attemptDefault: 1 second
Multiplier for retry delay on each attemptDefault: 2.0
Maximum delay between retriesDefault: 100x initial interval
Maximum number of retry attempts (0 = unlimited)Default: 0 (unlimited)
Error types that should not be retried
Exponential Backoff Formula
Retry delay calculation:Example: Default Policy
With default settings (initialInterval=1s, backoffCoefficient=2.0, maximumInterval=100s):
| Attempt | Delay Calculation | Actual Delay |
|---|---|---|
| 1 | 1s × 2^0 = 1s | 1s |
| 2 | 1s × 2^1 = 2s | 2s |
| 3 | 1s × 2^2 = 4s | 4s |
| 4 | 1s × 2^3 = 8s | 8s |
| 5 | 1s × 2^4 = 16s | 16s |
| 6 | 1s × 2^5 = 32s | 32s |
| 7 | 1s × 2^6 = 64s | 64s |
| 8 | 1s × 2^7 = 128s | 100s (capped) |
| 9 | 1s × 2^8 = 256s | 100s (capped) |
Activity Retry Policies
Configure retries when scheduling activities:- Go
- TypeScript
- Python
Workflow Retry Policies
Configure retries for workflows and child workflows:Server-Side Configuration
Default retry policies can be configured in dynamic config:Non-Retriable Errors
Specify error types that should fail immediately without retry:Error Matching
Error type matching rules:- Exact type name match -
"ValidationError"matchesValidationErrortype - Package path match -
"myapp/errors.ValidationError"matches fully qualified type - Wildcard match -
"*ValidationError"matches any package
Implementation in History Service
Implementation in History Service
Non-retriable error checking is implemented in
service/history/workflow/activity.go:Retry Timeouts
Retries interact with activity and workflow timeouts:Activity Timeouts
ScheduleToStart
Time from schedule to worker pickup. Retries reset this timeout.
StartToClose
Time for single attempt. Each retry gets full StartToClose timeout.
ScheduleToClose
Total time including all retries. Stops retry loop when exceeded.
Heartbeat
Heartbeat timeout. Retries reset on heartbeat timeout.
Retry Until ScheduleToClose
- ScheduleToCloseTimeout (10 minutes) is exceeded
- OR activity succeeds
- OR non-retriable error occurs
Best Practices
Use appropriate backoff for service dependencies
Use appropriate backoff for service dependencies
Match backoff to downstream service recovery time:
- Fast recovery (seconds):
initialInterval=1s,backoffCoefficient=1.5 - Slow recovery (minutes):
initialInterval=30s,backoffCoefficient=2.0 - Rate limited APIs:
initialInterval=5s,maximumInterval=5m
Limit retries for expensive operations
Limit retries for expensive operations
Set
maximumAttempts for costly activities:Mark validation errors as non-retriable
Mark validation errors as non-retriable
Don’t waste resources retrying permanent failures:
Use ScheduleToClose to bound total retry time
Use ScheduleToClose to bound total retry time
Prevent infinite retry loops:
Monitoring Retry Behavior
Key metrics for retry monitoring:- activity_task_schedule_to_start_latency - Time waiting for worker (increases with retries)
- activity_execution_failed - Failed activity attempts (includes retries)
- activity_execution_failed_total - Activities failed after all retries
- activity_retry_count - Number of retry attempts per activity
Implementation Details
Retry logic is implemented in:- Activity retries:
service/history/workflow/activity.go - Workflow retries:
service/history/workflow/mutable_state_impl.go - Backoff calculation:
common/backoff/retry.go - Timer scheduling: History Service timer queue
See Also
Activities
Learn about activity execution and timeouts
Workflows
Understand workflow execution model
History Service
Deep dive into retry implementation