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 {
1---2name: temporal-golang-pro3description: Use when building durable distributed systems with Temporal Go SDK. Covers deterministic workflow rules, mTLS worker configs, and advanced patterns.4---567# Temporal Go SDK (temporal-golang-pro)89## Overview1011Expert-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.1213## When to Use This Skill1415- **Designing Distributed Systems**: When building microservices that require durable state and reliable orchestration.16- **Implementing Complex Workflows**: Using the Go SDK to handle long-running processes (days/months) or complex Saga patterns.17- **Optimizing Performance**: When workers need fine-tuned concurrency, mTLS security, or custom interceptors.18- **Ensuring Reliability**: Implementing idempotent activities, graceful error handling, and sophisticated retry policies.19- **Maintenance & Evolution**: Versioning running workflows or performing zero-downtime worker updates.2021## Do not use this skill when2223- Using Temporal with other SDKs (Python, Java, TypeScript) - refer to their specific `-pro` skills.24- The task is a simple request/response without durability or coordination needs.25- High-level design without implementation (use `workflow-orchestration-patterns`).2627## Step-by-Step Guide28291. **Gather Context**: Proactively ask for:30 - Target **Temporal Cluster** (Cloud vs. Self-hosted) and **Namespace**.31 - **Task Queue** names and expected throughput.32 - **Security requirements** (mTLS paths, authentication).33 - **Failure modes** and desired retry/timeout policies.342. **Verify Determinism**: Before suggesting workflow code, verify against these **5 Rules**:35 - No native Go concurrency (goroutines).36 - No native time (`time.Now`, `time.Sleep`).37 - No non-deterministic map iteration (must sort keys).38 - No direct external I/O or network calls.39 - No non-deterministic random numbers.403. **Implement Incrementally**: Start with shared Protobuf/Data classes, then Activities, then Workflows, and finally Workers.414. **Leverage Resources**: If the implementation requires advanced patterns (Sagas, Interceptors, Replay Testing), explicitly refer to the implementation playbook and testing strategies.4243## Capabilities4445### Go SDK Implementation4647- **Worker Management**: Deep knowledge of `worker.Options`, including `MaxConcurrentActivityTaskPollers`, `WorkerStopTimeout`, and `StickyScheduleToStartTimeout`.48- **Interceptors**: Implementing Client, Worker, and Workflow interceptors for cross-cutting concerns (logging, tracing, auth).49- **Custom Data Converters**: Integrating Protobuf, encrypted payloads, or custom JSON marshaling.5051### Advanced Workflow Patterns5253- **Durable Concurrency**: Using `workflow.Go`, `workflow.Channel`, and `workflow.Selector` instead of native primitives.54- **Versioning**: Implementing safe code evolution using `workflow.GetVersion` and `workflow.GetReplaySafeLogger`.55- **Large-scale Processing**: Pattern for `ContinueAsNew` to manage history size limits (defaults: 50MB or 50K events).56- **Child Workflows**: Managing lifecycle, cancellation, and parent-child signal propagation.5758### Testing & Observability5960- **Testsuite Mastery**: Using `WorkflowTestSuite` for unit and functional testing with deterministic time control.61- **Mocking**: Sophisticated activity and child workflow mocking strategies.62- **Replay Testing**: Validating code changes against production event histories.63- **Metrics**: Configuring Prometheus/OpenTelemetry exporters for worker performance tracking.6465## Examples6667### Example 1: Versioned Workflow (Deterministic)6869```go70// Note: imports omitted. Requires 'go.temporal.io/sdk/workflow', 'go.temporal.io/sdk/temporal', and 'time'.71func SubscriptionWorkflow(ctx workflow.Context, userID string) error {72 // 1. Versioning for logic evolution (v1 = DefaultVersion)73 v := workflow.GetVersion(ctx, "billing_logic", workflow.DefaultVersion, 2)7475 for i := 0; i < 12; i++ {76 ao := workflow.ActivityOptions{77 StartToCloseTimeout: 5 * time.Minute,78 RetryPolicy: &temporal.RetryPolicy{MaximumAttempts: 3},79 }80 ctx = workflow.WithActivityOptions(ctx, ao)8182 // 2. Activity Execution (Always handle errors)83 err := workflow.ExecuteActivity(ctx, ChargePaymentActivity, userID).Get(ctx, nil)84 if err != nil {85 workflow.GetLogger(ctx).Error("Payment failed", "Error", err)86 return err87 }8889 // 3. Durable Sleep (Time-skipping safe)90 sleepDuration := 30 * 24 * time.Hour91 if v >= 2 {92 sleepDuration = 28 * 24 * time.Hour93 }9495 if err := workflow.Sleep(ctx, sleepDuration); err != nil {96 return err97 }98 }99 return nil100}101```102103### Example 2: Full mTLS Worker Setup104105```go106func RunSecureWorker() error {107 // 1. Load Client Certificate and Key108 cert, err := tls.LoadX509KeyPair("client.pem", "client.key")109 if err != nil {110