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. 4category: AI & Agents5source: antigravity6tags: [python, typescript, api, ai, workflow, design, security, rag, cro]7url: https://github.com/sickn33/antigravity-awesome-skills/tree/main/skills/temporal-golang-pro8metadata:9 source: https://skillmd.com/skills/sickn33/temporal-golang-pro10---111213# Temporal Go SDK (temporal-golang-pro)1415## Overview1617Expert-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.1819## When to Use This Skill2021- **Designing Distributed Systems**: When building microservices that require durable state and reliable orchestration.22- **Implementing Complex Workflows**: Using the Go SDK to handle long-running processes (days/months) or complex Saga patterns.23- **Optimizing Performance**: When workers need fine-tuned concurrency, mTLS security, or custom interceptors.24- **Ensuring Reliability**: Implementing idempotent activities, graceful error handling, and sophisticated retry policies.25- **Maintenance & Evolution**: Versioning running workflows or performing zero-downtime worker updates.2627## Do not use this skill when2829- Using Temporal with other SDKs (Python, Java, TypeScript) - refer to their specific `-pro` skills.30- The task is a simple request/response without durability or coordination needs.31- High-level design without implementation (use `workflow-orchestration-patterns`).3233## Step-by-Step Guide34351. **Gather Context**: Proactively ask for:36 - Target **Temporal Cluster** (Cloud vs. Self-hosted) and **Namespace**.37 - **Task Queue** names and expected throughput.38 - **Security requirements** (mTLS paths, authentication).39 - **Failure modes** and desired retry/timeout policies.402. **Verify Determinism**: Before suggesting workflow code, verify against these **5 Rules**:41 - No native Go concurrency (goroutines).42 - No native time (`time.Now`, `time.Sleep`).43 - No non-deterministic map iteration (must sort keys).44 - No direct external I/O or network calls.45 - No non-deterministic random numbers.463. **Implement Incrementally**: Start with shared Protobuf/Data classes, then Activities, then Workflows, and finally Workers.474. **Leverage Resources**: If the implementation requires advanced patterns (Sagas, Interceptors, Replay Testing), explicitly refer to the implementation playbook and testing strategies.4849## Capabilities5051### Go SDK Implementation5253- **Worker Management**: Deep knowledge of `worker.Options`, including `MaxConcurrentActivityTaskPollers`, `WorkerStopTimeout`, and `StickyScheduleToStartTimeout`.54- **Interceptors**: Implementing Client, Worker, and Workflow interceptors for cross-cutting concerns (logging, tracing, auth).55- **Custom Data Converters**: Integrating Protobuf, encrypted payloads, or custom JSON marshaling.5657### Advanced Workflow Patterns5859- **Durable Concurrency**: Using `workflow.Go`, `workflow.Channel`, and `workflow.Selector` instead of native primitives.60- **Versioning**: Implementing safe code evolution using `workflow.GetVersion` and `workflow.GetReplaySafeLogger`.61- **Large-scale Processing**: Pattern for `ContinueAsNew` to manage history size limits (defaults: 50MB or 50K events).62- **Child Workflows**: Managing lifecycle, cancellation, and parent-child signal propagation.6364### Testing & Observability6566- **Testsuite Mastery**: Using `WorkflowTestSuite` for unit and functional testing with deterministic time control.67- **Mocking**: Sophisticated activity and child workflow mocking strategies.68- **Replay Testing**: Validating code changes against production event histories.69- **Metrics**: Configuring Prometheus/OpenTelemetry exporters for worker performance tracking.7071## Examples7273### Example 1: Versioned Workflow (Deterministic)7475```go76// Note: imports omitted. Requires 'go.temporal.io/sdk/workflow', 'go.temporal.io/sdk/temporal', and 'time'.77func SubscriptionWorkflow(ctx workflow.Context, userID string) error {78 // 1. Versioning for logic evolution (v1 = DefaultVersion)79 v := workflow.GetVersion(ctx, "billing_logic", workflow.DefaultVersion, 2)8081 for i := 0; i < 12; i++ {82 ao := workflow.ActivityOptions{83 StartToCloseTimeout: 5 * time.Minute,84 RetryPolicy: &temporal.RetryPolicy{MaximumAttempts: 3},85 }86 ctx = workflow.WithActivityOptions(ctx, ao)8788 // 2. Activity Execution (Always handle errors)89 err := workflow.ExecuteActivity(ctx, ChargePaymentActivity, userID).Get(ctx, nil)90 if err != nil {91 workflow.GetLogger(ctx).Error("Payment failed", "Error", err)92 return err93 }9495 // 3. Durable Sleep (Time-skipping safe)96 sleepDuration := 30 * 24 * time.Hour97 if v >= 2 {98 sleepDuration = 28 * 24 * time.Hour99 }100101 if err := workflow.Sleep(ctx, sleepDuration); err != nil {102 return err103 }104 }105 return nil106}107```108109### Example 2: Full mTLS Worker Setup110111```go112func RunSecureWorker() error {113 // 1. Load Client Certificate and Key114 cert, err := tls.LoadX509KeyPair("client.pem", "client.key")115 if err != nil {116