A comprehensive example application demonstrating Temporal workflow framework patterns and best practices using Go.
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
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
- Go 1.21 or later
- Docker and Docker Compose
- Make (optional, for convenience commands)
-
Start Temporal Server
make setup
This starts Temporal server with PostgreSQL backend using Docker Compose.
-
Start the Worker (in one terminal)
make worker
-
Run Examples (in another terminal)
make client
-
View Temporal Web UI Open http://localhost:8080 in your browser to see workflow executions.
If you prefer to run commands manually:
-
Start Temporal Server
cd deployments sudo docker compose up -d -
Start Worker
go run ./cmd/worker
-
Run Client
go run ./cmd/client
Build all applications:
make buildOr build individually:
make build-worker # Creates bin/worker
make build-client # Creates bin/clientRun the test suite:
make testDemonstrates a complete e-commerce order processing pipeline:
- Validate Order - Validates order data
- Reserve Inventory - Reserves items in inventory
- Process Payment - Charges the customer
- Fulfill Order - Ships the order
- 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
Shows how to create workflows that:
- Use timers for delays
- Can be paused and resumed
- Maintain state across restarts
Demonstrates:
- Parallel execution of multiple child workflows
- Collecting results from all children
- Error handling in parent-child relationships
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
The Temporal server is configured via deployments/docker-compose.yml:
- PostgreSQL backend for persistence
- Web UI on port 8080
- gRPC API on port 7233
Custom Temporal settings are in deployments/dynamicconfig/development-sql.yaml.
- Create workflow function in
internal/workflows/ - Register it in
cmd/worker/main.go - Add client code in
cmd/client/main.go - Write tests in
internal/workflows/*_test.go
- Create activity function in
internal/activities/ - Register it in
cmd/worker/main.go - Use it in workflows
- 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/
Stop Temporal server and clean up:
make clean- Port conflicts: Ensure ports 7233 and 8080 are available
- Docker permissions: Commands use
sudofor Docker Compose - Go path: Makefile sets Go path automatically
View Temporal server logs:
make logsmake clean
make setup