Introduction
The Cadence Go SDK is the official client library for building workflows and activities in Go. It provides a type-safe, idiomatic Go API for defining durable workflows that can run for days, months, or years.GitHub Repository
Official Cadence Go Client SDK - Star and contribute on GitHub
Installation
Prerequisites
- Go 1.18 or higher
- Cadence server running (local or remote)
Add Dependency
Import Packages
Quick Start
1. Define a Workflow
Workflows must be deterministic and cannot directly call external services:2. Define an Activity
Activities perform the actual work and can call external services:3. Start a Worker
Workers poll for tasks and execute workflows and activities:4. Execute a Workflow
Start workflow execution from your application:Advanced Patterns
Child Workflows
Orchestrate complex processes by composing workflows:Signals and Queries
- Signals
- Queries
Signals allow external systems to send commands to running workflows:
Error Handling and Retries
Local Activities
Local activities are optimized for short, fast operations:Worker Configuration
Tuning Worker Performance
Worker Lifecycle Management
Testing
Unit Testing Workflows
Sample Repository
Cadence Go Samples
Complete examples including:
- Hello World workflows
- Error handling and retries
- Signal and query patterns
- Child workflow orchestration
- Timer and sleep operations
- Saga pattern implementation
Best Practices
Workflow Determinism
Workflow Determinism
- Never use
time.Now()orrand.Random()directly - Use
workflow.Now()andworkflow.NewRandom() - Don’t call external services from workflow code
- Use activities for all non-deterministic operations
Activity Design
Activity Design
- Keep activities idempotent when possible
- Implement heartbeats for long-running activities
- Use appropriate timeout values
- Handle transient errors with retry policies
Worker Configuration
Worker Configuration
- Start with default settings and tune based on metrics
- Monitor queue depth and adjust poller counts
- Use sticky execution for better performance
- Implement graceful shutdown handlers
Error Handling
Error Handling
- Define clear retry policies for activities
- Use typed errors for better error classification
- Implement compensation logic for saga patterns
- Log context information for debugging
Next Steps
Core Concepts
Understand workflows, activities, and task lists
Java Client
Explore the Java SDK for JVM applications
CLI Reference
Manage workflows with the Cadence CLI
Web UI
Monitor workflows visually