This guide covers best practices and conventions for developing Temporal Server.
Code Style
Follow Project Conventions
Rigorously adhere to existing project conventions. Always analyze surrounding code, tests, and configuration before making changes.
Key principles:
- Mimic the style (formatting, naming), structure, and architectural patterns of existing code
- Understand local context (imports, functions, interfaces) to ensure changes integrate naturally
- Never introduce new patterns without discussing with maintainers
Add comments sparingly. Focus on why something is done, not what is done:
For future design considerations, use:
Use the project’s formatting tools:
Error Handling
Always Handle Errors
Errors MUST be handled, never ignored.
Logging Errors
Use appropriate logging methods based on severity:
Wrapping Errors
Provide context when wrapping errors:
Testing Best Practices
Write Tests for New Functionality
All new features require tests covering:
- Best-case scenarios
- Failure modes
- Edge cases
- Error handling
Test Organization
Prefer require Over assert
Avoid Testify Suites in Unit Tests
Testify suites are required for functional tests but should be avoided in unit tests:
Use require.Eventually Instead of time.Sleep
Run Tests After Changes
Dependency Management
Never Assume Libraries Are Available
Do not introduce new third-party libraries unless specifically requested or approved by maintainers.
Before using any library:
- Check if it exists in
go.mod
- Look for existing usage patterns in the codebase
- Verify it’s appropriate for the use case
Updating Dependencies
Code Generation
When to Regenerate Code
Regenerate code after modifying:
Proto files:
Files with //go:generate directives:
Example //go:generate directive:
Verify Generated Code
After regenerating code:
Linting and Validation
Run Linters Before Committing
Fix Linting Issues
Many linting issues can be auto-fixed:
Breaking Changes
Verify proto changes don’t break compatibility:
All source files require license headers. Verify:
Commit Messages
Follow the Chris Beams guide for commit messages:
- Separate subject from body with a blank line
- Limit subject line to 50 characters
- Capitalize the subject line
- Do not end the subject line with a period
- Use imperative mood (“Add feature” not “Added feature”)
- Wrap body at 72 characters
- Use body to explain what and why, not how
Example:
Pull Request Titles
PR titles should:
- Start with an uppercase letter
- Have no period at the end
- Not use generic titles like “bug fixes” or “updates”
- Clearly describe the change
Good PR titles:
- “Add validation for workflow update requests”
- “Fix race condition in history service shutdown”
- “Improve performance of task queue matching”
Bad PR titles:
- “bug fixes”
- “updates.”
- “fix stuff”
Project Structure
Understand the project layout:
/api - Proto definitions and generated code
/chasm - Chasm library (Coordinated Heterogeneous Application State Machines)
/client - Client libraries for inter-service communication
/cmd - CLI commands and main applications
/common - Shared modules across all services
/common/dynamicconfig - Dynamic configuration
/common/membership - Cluster membership
/common/metrics - Metrics definitions
/common/namespace - Namespace cache
/common/persistence - Persistence layer
/components - Nexus components
/config - Configuration files
/proto - Internal proto definitions
/schema - Database schemas
/service - Main services
/service/frontend - Frontend service
/service/history - History service
/service/matching - Matching service
/service/worker - Worker service
/tests - Functional tests
Important Make Targets
Common Commands
Development Workflow
CI Build Steps
The CI runs these checks:
This includes:
- Proto compilation
- Code generation
- Breaking change detection
- Shell script checking
- Import formatting
- Go mod tidy
- Verification that all generated code is committed
Debugging
Running Server Locally
Start the server with different persistence options:
IDE Debugging (GoLand)
To debug the server:
- Set Run Type to “package”
- Package path:
go.temporal.io/server/cmd/server
- Program arguments:
For other databases:
See GoLand Debugging documentation for details.
Contributor License Agreement
All contributors must sign the Temporal Contributor License Agreement before we can merge changes.
Getting Help
Additional Resources