Temporal Go SDK (temporal-golang-pro)
Overview
Expert-level guide for building resilient, scalable, and deterministic distributed systems using the Temporal Go SDK. This skill transforms vague orchestration requirements into production-grade Go implementations, focusing on durable execution, strict determinism, and enterprise-scale worker configuration.
When to Use This Skill
- Designing Distributed Systems: When building microservices that require durable state and reliable orchestration.
- Implementing Complex Workflows: Using the Go SDK to handle long-running processes (days/months) or complex Saga patterns.
- Optimizing Performance: When workers need fine-tuned concurrency, mTLS security, or custom interceptors.
- Ensuring Reliability: Implementing idempotent activities, graceful error handling, and sophisticated retry policies.
- Maintenance & Evolution: Versioning running workflows or performing zero-downtime worker updates.
Do not use this skill when
- Using Temporal with other SDKs (Python, Java, TypeScript) - refer to their specific
-pro skills.
- The task is a simple request/response without durability or coordination needs.
- High-level design without implementation (use
workflow-orchestration-patterns).
Step-by-Step Guide
- Gather Context: Proactively ask for:
- Target Temporal Cluster (Cloud vs. Self-hosted) and Namespace.
- Task Queue names and expected throughput.
- Security requirements (mTLS paths, authentication).
- Failure modes and desired retry/timeout policies.
- Verify Determinism: Before suggesting workflow code, verify against these 5 Rules:
- No native Go concurrency (goroutines).
- No native time (
time.Now, time.Sleep).
- No non-deterministic map iteration (must sort keys).
- No direct external I/O or network calls.
- No non-deterministic random numbers.
- Implement Incrementally: Start with shared Protobuf/Data classes, then Activities, then Workflows, and finally Workers.
- Leverage Resources: If the implementation requires advanced patterns (Sagas, Interceptors, Replay Testing), explicitly refer to the implementation playbook and testing strategies.
Capabilities
Go SDK Implementation
- Worker Management: Deep knowledge of
worker.Options, including MaxConcurrentActivityTaskPollers, WorkerStopTimeout, and StickyScheduleToStartTimeout.
- Interceptors: Implementing Client, Worker, and Workflow interceptors for cross-cutting concerns (logging, tracing, auth).
- Custom Data Converters: Integrating Protobuf, encrypted payloads, or custom JSON marshaling.
Advanced Workflow Patterns
- Durable Concurrency: Using
workflow.Go, workflow.Channel, and workflow.Selector instead of native primitives.
- Versioning: Implementing safe code evolution using
workflow.GetVersion and workflow.GetReplaySafeLogger.
- Large-scale Processing: Pattern for
ContinueAsNew to manage history size limits (defaults: 50MB or 50K events).
- Child Workflows: Managing lifecycle, cancellation, and parent-child signal propagation.
Testing & Observability
- Testsuite Mastery: Using
WorkflowTestSuite for unit and functional testing with deterministic time control.
- Mocking: Sophisticated activity and child workflow mocking strategies.
- Replay Testing: Validating code changes against production event histories.
- Metrics: Configuring Prometheus/OpenTelemetry exporters for worker performance tracking.
Examples
Example 1: Versioned Workflow (Deterministic)
// Note: imports omitted. Requires 'go.temporal.io/sdk/workflow', 'go.temporal.io/sdk/temporal', and 'time'.
func SubscriptionWorkflow(ctx workflow.Context, userID string) error {
// 1. Versioning for logic evolution (v1 = DefaultVersion)
v := workflow.GetVersion(ctx, "billing_logic", workflow.DefaultVersion, 2)
for i := 0; i < 12; i++ {
ao := workflow.ActivityOptions{
StartToCloseTimeout: 5 * time.Minute,
RetryPolicy: &temporal.RetryPolicy{MaximumAttempts: 3},
}
ctx = workflow.WithActivityOptions(ctx, ao)
// 2. Activity Execution (Always handle errors)
err := workflow.ExecuteActivity(ctx, ChargePaymentActivity, userID).Get(ctx, nil)
if err != nil {
workflow.GetLogger(ctx).Error("Payment failed", "Error", err)
return err
}
// 3. Durable Sleep (Time-skipping safe)
sleepDuration := 30 * 24 * time.Hour
if v >= 2 {
sleepDuration = 28 * 24 * time.Hour
}
if err := workflow.Sleep(ctx, sleepDuration); err != nil {
return err
}
}
return nil
}
Example 2: Full mTLS Worker Setup
func RunSecureWorker() error {
// 1. Load Client Certificate and Key
cert, err := tls.LoadX509KeyPair("client.pem", "client.key")
if err != nil {
return fmt.Errorf("failed to load client keys: %w", err)
}
// 2. Load CA Certificate for Server verification (Proper mTLS)
caPem, err := os.ReadFile("ca.pem")
if err != nil {
return fmt.Errorf("failed to read CA cert: %w", err)
}
certPool := x509.NewCertPool()
if !certPool.AppendCertsFromPEM(caPem) {
return fmt.Errorf("failed to parse CA cert")
}
// 3. Dial Cluster with full TLS config
c, err := client.Dial(client.Options{
HostPort: "temporal.example.com:7233",
Namespace: "production",
ConnectionOptions: client.ConnectionOptions{
TLS: &tls.Config{
Certificates: []tls.Certificate{cert},
RootCAs: certPool,
},
},
})
if err != nil {
return fmt.Errorf("failed to dial temporal: %w", err)
}
defer c.Close()
w := worker.New(c, "payment-queue", worker.Options{})
w.RegisterWorkflow(SubscriptionWorkflow)
if err := w.Run(worker.InterruptCh()); err != nil {
return fmt.Errorf("worker run failed: %w", err)
}
return nil
}
Example 3: Selector & Signal Integration
func ApprovalWorkflow(ctx workflow.Context) (string, error) {
var approved bool
signalCh := workflow.GetSignalChannel(ctx, "approval-signal")
// Use Selector to wait for multiple async events
s := workflow.NewSelector(ctx)
s.AddReceive(signalCh, func(c workflow.ReceiveChannel, _ bool) {
c.Receive(ctx, &approved)
})
// Add 72-hour timeout timer
s.AddReceive(workflow.NewTimer(ctx, 72*time.Hour).GetChannel(), func(c workflow.ReceiveChannel, _ bool) {
approved = false
})
s.Select(ctx)
if !approved {
return "rejected", nil
}
return "approved", nil
}
Best Practices
- ✅ Do: Always handle errors from
ExecuteActivity and client.Dial.
- ✅ Do: Use
workflow.Go and workflow.Channel for concurrency.
- ✅ Do: Sort map keys before iteration to maintain determinism.
- ✅ Do: Use
activity.RecordHeartbeat for activities lasting > 1 minute.
- ✅ Do: Test logic compatibility using
replayer.ReplayWorkflowHistoryFromJSON.
- ❌ Don't: Swallow errors with
_ or log.Fatal in production workers.
- ❌ Don't: Perform direct Network/Disk I/O inside a Workflow function.
- ❌ Don't: Rely on native
time.Now() or rand.Int().
- ❌ Don't: Apply this to simple cron jobs that don't require durability.
Troubleshooting
- Panic: Determinism Mismatch: Usually caused by logic changes without
workflow.GetVersion or non-deterministic code (e.g., native maps).
- Error: History Size Exceeded: History limit reached (default 50K events). Ensure
ContinueAsNew is implemented.
- Worker Hang: Check
WorkerStopTimeout and ensure all activities handle context cancellation.
Limitations
- Does not cover Temporal Cloud UI navigation or TLS certificate provisioning workflows.
- Does not cover Temporal Java, Python, or TypeScript SDKs; refer to their dedicated
-pro skills.
- Assumes Temporal Server v1.20+ and Go SDK v1.25+; older SDK versions may have different APIs.
- Does not cover experimental Temporal features (e.g., Nexus, Multi-cluster Replication).
- Does not address global namespace configuration or multi-region failover setup.
- Does not cover Temporal Worker versioning via the
worker-versioning feature flag (experimental).
Resources
Related Skills
grpc-golang - Internal transport protocol and Protobuf design.
golang-pro - General Go performance tuning and advanced syntax.
workflow-orchestration-patterns - Language-agnostic orchestration strategy.
1---
2name: temporal-golang-pro
3description: "Use when building durable distributed systems with Temporal Go SDK. Covers deterministic workflow rules, mTLS worker configs, and advanced patterns."
4version: 1.0.0
5author:
6 name: "sickn33 / Antigravity Community"
7 github: sickn33
8tags: [temporal, golang, pro, workflow]
9category: workflow
10platforms: [macos, linux, windows]
11license: MIT
12metadata:
13 hermes:
14 source: https://skillmd.com/skills/nous-hermeshub/temporal-golang-pro
15 upstream: "antigravity-awesome-skills"
16 risk: "safe"
17 date_added: "2026-02-27"
18 original_author: "Antigravity Community"
19---
20
21# Temporal Go SDK (temporal-golang-pro)
22
23## Overview
24
25Expert-level guide for building resilient, scalable, and deterministic distributed systems using the Temporal Go SDK. This skill transforms vague orchestration requirements into production-grade Go implementations, focusing on durable execution, strict determinism, and enterprise-scale worker configuration.
26
27## When to Use This Skill
28
29- **Designing Distributed Systems**: When building microservices that require durable state and reliable orchestration.
30- **Implementing Complex Workflows**: Using the Go SDK to handle long-running processes (days/months) or complex Saga patterns.
31- **Optimizing Performance**: When workers need fine-tuned concurrency, mTLS security, or custom interceptors.
32- **Ensuring Reliability**: Implementing idempotent activities, graceful error handling, and sophisticated retry policies.
33- **Maintenance & Evolution**: Versioning running workflows or performing zero-downtime worker updates.
34
35## Do not use this skill when
36
37- Using Temporal with other SDKs (Python, Java, TypeScript) - refer to their specific `-pro` skills.
38- The task is a simple request/response without durability or coordination needs.
39- High-level design without implementation (use `workflow-orchestration-patterns`).
40
41## Step-by-Step Guide
42
431. **Gather Context**: Proactively ask for:
44 - Target **Temporal Cluster** (Cloud vs. Self-hosted) and **Namespace**.
45 - **Task Queue** names and expected throughput.
46 - **Security requirements** (mTLS paths, authentication).
47 - **Failure modes** and desired retry/timeout policies.
482. **Verify Determinism**: Before suggesting workflow code, verify against these **5 Rules**:
49 - No native Go concurrency (goroutines).
50 - No native time (`time.Now`, `time.Sleep`).
51 - No non-deterministic map iteration (must sort keys).
52 - No direct external I/O or network calls.
53 - No non-deterministic random numbers.
543. **Implement Incrementally**: Start with shared Protobuf/Data classes, then Activities, then Workflows, and finally Workers.
554. **Leverage Resources**: If the implementation requires advanced patterns (Sagas, Interceptors, Replay Testing), explicitly refer to the implementation playbook and testing strategies.
56
57## Capabilities
58
59### Go SDK Implementation
60
61- **Worker Management**: Deep knowledge of `worker.Options`, including `MaxConcurrentActivityTaskPollers`, `WorkerStopTimeout`, and `StickyScheduleToStartTimeout`.
62- **Interceptors**: Implementing Client, Worker, and Workflow interceptors for cross-cutting concerns (logging, tracing, auth).
63- **Custom Data Converters**: Integrating Protobuf, encrypted payloads, or custom JSON marshaling.
64
65### Advanced Workflow Patterns
66
67- **Durable Concurrency**: Using `workflow.Go`, `workflow.Channel`, and `workflow.Selector` instead of native primitives.
68- **Versioning**: Implementing safe code evolution using `workflow.GetVersion` and `workflow.GetReplaySafeLogger`.
69- **Large-scale Processing**: Pattern for `ContinueAsNew` to manage history size limits (defaults: 50MB or 50K events).
70- **Child Workflows**: Managing lifecycle, cancellation, and parent-child signal propagation.
71
72### Testing & Observability
73
74- **Testsuite Mastery**: Using `WorkflowTestSuite` for unit and functional testing with deterministic time control.
75- **Mocking**: Sophisticated activity and child workflow mocking strategies.
76- **Replay Testing**: Validating code changes against production event histories.
77- **Metrics**: Configuring Prometheus/OpenTelemetry exporters for worker performance tracking.
78
79## Examples
80
81### Example 1: Versioned Workflow (Deterministic)
82
83```go
84// Note: imports omitted. Requires 'go.temporal.io/sdk/workflow', 'go.temporal.io/sdk/temporal', and 'time'.
85func SubscriptionWorkflow(ctx workflow.Context, userID string) error {
86 // 1. Versioning for logic evolution (v1 = DefaultVersion)
87 v := workflow.GetVersion(ctx, "billing_logic", workflow.DefaultVersion, 2)
88
89 for i := 0; i < 12; i++ {
90 ao := workflow.ActivityOptions{
91 StartToCloseTimeout: 5 * time.Minute,
92 RetryPolicy: &temporal.RetryPolicy{MaximumAttempts: 3},
93 }
94 ctx = workflow.WithActivityOptions(ctx, ao)
95
96 // 2. Activity Execution (Always handle errors)
97 err := workflow.ExecuteActivity(ctx, ChargePaymentActivity, userID).Get(ctx, nil)
98 if err != nil {
99 workflow.GetLogger(ctx).Error("Payment failed", "Error", err)
100 return err
101 }
102
103 // 3. Durable Sleep (Time-skipping safe)
104 sleepDuration := 30 * 24 * time.Hour
105 if v >= 2 {
106 sleepDuration = 28 * 24 * time.Hour
107 }
108
109 if err := workflow.Sleep(ctx, sleepDuration); err != nil {
110 return err
111 }
112 }
113 return nil
114}
115```
116
117### Example 2: Full mTLS Worker Setup
118
119```go
120func RunSecureWorker() error {
121 // 1. Load Client Certificate and Key
122 cert, err := tls.LoadX509KeyPair("client.pem", "client.key")
123 if err != nil {
124 return fmt.Errorf("failed to load client keys: %w", err)
125 }
126
127 // 2. Load CA Certificate for Server verification (Proper mTLS)
128 caPem, err := os.ReadFile("ca.pem")
129 if err != nil {
130 return fmt.Errorf("failed to read CA cert: %w", err)
131 }
132 certPool := x509.NewCertPool()
133 if !certPool.AppendCertsFromPEM(caPem) {
134 return fmt.Errorf("failed to parse CA cert")
135 }
136
137 // 3. Dial Cluster with full TLS config
138 c, err := client.Dial(client.Options{
139 HostPort: "temporal.example.com:7233",
140 Namespace: "production",
141 ConnectionOptions: client.ConnectionOptions{
142 TLS: &tls.Config{
143 Certificates: []tls.Certificate{cert},
144 RootCAs: certPool,
145 },
146 },
147 })
148 if err != nil {
149 return fmt.Errorf("failed to dial temporal: %w", err)
150 }
151 defer c.Close()
152
153 w := worker.New(c, "payment-queue", worker.Options{})
154 w.RegisterWorkflow(SubscriptionWorkflow)
155
156 if err := w.Run(worker.InterruptCh()); err != nil {
157 return fmt.Errorf("worker run failed: %w", err)
158 }
159 return nil
160}
161```
162
163### Example 3: Selector & Signal Integration
164
165```go
166func ApprovalWorkflow(ctx workflow.Context) (string, error) {
167 var approved bool
168 signalCh := workflow.GetSignalChannel(ctx, "approval-signal")
169
170 // Use Selector to wait for multiple async events
171 s := workflow.NewSelector(ctx)
172 s.AddReceive(signalCh, func(c workflow.ReceiveChannel, _ bool) {
173 c.Receive(ctx, &approved)
174 })
175
176 // Add 72-hour timeout timer
177 s.AddReceive(workflow.NewTimer(ctx, 72*time.Hour).GetChannel(), func(c workflow.ReceiveChannel, _ bool) {
178 approved = false
179 })
180
181 s.Select(ctx)
182
183 if !approved {
184 return "rejected", nil
185 }
186 return "approved", nil
187}
188```
189
190## Best Practices
191
192- ✅ **Do:** Always handle errors from `ExecuteActivity` and `client.Dial`.
193- ✅ **Do:** Use `workflow.Go` and `workflow.Channel` for concurrency.
194- ✅ **Do:** Sort map keys before iteration to maintain determinism.
195- ✅ **Do:** Use `activity.RecordHeartbeat` for activities lasting > 1 minute.
196- ✅ **Do:** Test logic compatibility using `replayer.ReplayWorkflowHistoryFromJSON`.
197- ❌ **Don't:** Swallow errors with `_` or `log.Fatal` in production workers.
198- ❌ **Don't:** Perform direct Network/Disk I/O inside a Workflow function.
199- ❌ **Don't:** Rely on native `time.Now()` or `rand.Int()`.
200- ❌ **Don't:** Apply this to simple cron jobs that don't require durability.
201
202## Troubleshooting
203
204- **Panic: Determinism Mismatch**: Usually caused by logic changes without `workflow.GetVersion` or non-deterministic code (e.g., native maps).
205- **Error: History Size Exceeded**: History limit reached (default 50K events). Ensure `ContinueAsNew` is implemented.
206- **Worker Hang**: Check `WorkerStopTimeout` and ensure all activities handle context cancellation.
207
208## Limitations
209
210- Does not cover Temporal Cloud UI navigation or TLS certificate provisioning workflows.
211- Does not cover Temporal Java, Python, or TypeScript SDKs; refer to their dedicated `-pro` skills.
212- Assumes Temporal Server v1.20+ and Go SDK v1.25+; older SDK versions may have different APIs.
213- Does not cover experimental Temporal features (e.g., Nexus, Multi-cluster Replication).
214- Does not address global namespace configuration or multi-region failover setup.
215- Does not cover Temporal Worker versioning via the `worker-versioning` feature flag (experimental).
216
217## Resources
218
219- [Implementation Playbook](resources/implementation-playbook.md) - Deep dive into Go SDK patterns.
220- [Testing Strategies](resources/testing-strategies.md) - Unit, Replay, and Integration testing for Go.
221- [Temporal Go SDK Reference](https://pkg.go.dev/go.temporal.io/sdk)
222- [Temporal Go Samples](https://github.com/temporalio/samples-go)
223
224## Related Skills
225
226- `grpc-golang` - Internal transport protocol and Protobuf design.
227- `golang-pro` - General Go performance tuning and advanced syntax.
228- `workflow-orchestration-patterns` - Language-agnostic orchestration strategy.