Skip to content

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Temporal Go Example Application

A comprehensive example application demonstrating Temporal workflow framework patterns and best practices using Go.

Project Structure

This project follows the Standard Go Project Layout:

/
├── cmd/                    # Main applications
│   ├── worker/            # Temporal worker application
│   └── client/            # Client application for running workflows
├── internal/              # Private application code
│   ├── activities/        # Temporal activities
│   └── workflows/         # Temporal workflows
├── pkg/                   # Public library code
│   └── models/           # Shared data models
├── deployments/          # Docker Compose and deployment configs
│   ├── docker-compose.yml
│   └── dynamicconfig/
├── scripts/              # Build and deployment scripts
├── docs/                 # Documentation
├── bin/                  # Compiled binaries (created by build)
├── go.mod
├── go.sum
└── Makefile

Features

This example demonstrates:

  • Order Processing Workflow: A complete e-commerce order processing pipeline with SAGA pattern
  • Long-Running Workflows: Workflows that use timers and can be resumed
  • Parent-Child Workflows: Parallel processing of multiple orders
  • Error Handling & Compensation: Proper error handling with compensation activities
  • Activity Retries: Configurable retry policies for activities
  • Unit Testing: Comprehensive test suite using Temporal's test framework

Prerequisites

  • Go 1.21 or later
  • Docker and Docker Compose
  • Make (optional, for convenience commands)

Quick Start

  1. Start Temporal Server

    make setup

    This starts Temporal server with PostgreSQL backend using Docker Compose.

  2. Start the Worker (in one terminal)

    make worker
  3. Run Examples (in another terminal)

    make client
  4. View Temporal Web UI Open http://localhost:8080 in your browser to see workflow executions.

Manual Setup

If you prefer to run commands manually:

  1. Start Temporal Server

    cd deployments
    sudo docker compose up -d
  2. Start Worker

    go run ./cmd/worker
  3. Run Client

    go run ./cmd/client

Building

Build all applications:

make build

Or build individually:

make build-worker  # Creates bin/worker
make build-client  # Creates bin/client

Testing

Run the test suite:

make test

Workflows

Order Processing Workflow

Demonstrates a complete e-commerce order processing pipeline:

  1. Validate Order - Validates order data
  2. Reserve Inventory - Reserves items in inventory
  3. Process Payment - Charges the customer
  4. Fulfill Order - Ships the order
  5. Send Notification - Notifies customer of completion

The workflow implements the SAGA pattern with compensation activities:

  • If payment fails → Release inventory reservation
  • If fulfillment fails → Refund payment and release inventory

Long Running Workflow

Shows how to create workflows that:

  • Use timers for delays
  • Can be paused and resumed
  • Maintain state across restarts

Parent-Child Workflow

Demonstrates:

  • Parallel execution of multiple child workflows
  • Collecting results from all children
  • Error handling in parent-child relationships

Activities

All activities are located in internal/activities/ and include:

  • ValidateOrder - Order validation logic
  • ReserveInventory - Inventory management
  • ProcessPayment - Payment processing
  • FulfillOrder - Order fulfillment
  • SendNotification - Customer notifications
  • ReleaseInventory - Compensation activity
  • RefundPayment - Compensation activity

Configuration

Temporal Server Configuration

The Temporal server is configured via deployments/docker-compose.yml:

  • PostgreSQL backend for persistence
  • Web UI on port 8080
  • gRPC API on port 7233

Dynamic Configuration

Custom Temporal settings are in deployments/dynamicconfig/development-sql.yaml.

Development

Adding New Workflows

  1. Create workflow function in internal/workflows/
  2. Register it in cmd/worker/main.go
  3. Add client code in cmd/client/main.go
  4. Write tests in internal/workflows/*_test.go

Adding New Activities

  1. Create activity function in internal/activities/
  2. Register it in cmd/worker/main.go
  3. Use it in workflows

Project Layout Benefits

  • Separation of Concerns: Clear boundaries between different components
  • Testability: Easy to test individual components in isolation
  • Maintainability: Standard structure makes code easy to navigate
  • Scalability: Easy to add new workflows and activities
  • Reusability: Shared models and utilities in pkg/

Cleanup

Stop Temporal server and clean up:

make clean

Troubleshooting

Common Issues

  1. Port conflicts: Ensure ports 7233 and 8080 are available
  2. Docker permissions: Commands use sudo for Docker Compose
  3. Go path: Makefile sets Go path automatically

Logs

View Temporal server logs:

make logs

Reset Everything

make clean
make setup

Learn More

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages