Skip to content

Add Go, Python, and Java Saga design-pattern samples - #320

Merged
Duncanma merged 1 commit into
mainfrom
docs/design-pattern-saga-go-python-java
Dec 3, 2026
Merged

Duncanma merged 1 commit into
mainfrom
docs/design-pattern-saga-go-python-java

Conversation

@Duncanma

@Duncanma Duncanma commented Dec 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Adds runnable, tested Saga samples for Go, Python, and Java so the Saga pattern page can sync all four language tabs with Snipsync. The TypeScript tab already syncs from typescript-sandbox/src/design-patterns/saga/.

The code is ported from sandbox-runner/patterns/saga/ in temporal-sa/temporal-design-patterns, the project these docs pages came from, and changed to match the existing TypeScript sample and the page's guidance:

  • Same shape in every language. The request fields, the design-patterns-saga Task Queue, the Compensation: ... log lines, and the outcome match TypeScript. addBankAccount fails with a non-retryable error, the Workflow runs the three compensations in reverse order, and then re-throws, so the run ends FAILED. The temporal-sa Java and Python versions returned a status string instead.
  • Compensations survive cancellation. Go uses workflow.NewDisconnectedContext, Python catches asyncio.CancelledError, Java uses Workflow.newDetachedCancellationScope, and TypeScript uses CancellationScope.nonCancellable.
  • A failing compensation doesn't stop the rest. Each one is logged and the loop continues. Java sets Saga.Options.setContinueWithError(true).

The TypeScript Workflow gets the same two changes so the page's four tabs teach the same thing.

Layout

Language Path Snippet ID
Go go-sandbox/design-patterns/saga/ (package saga, plus worker/ and starter/) go-pattern-saga-pattern-workflow
Python python-sandbox/design-patterns/saga/ (own pyproject.toml and uv.lock, like the cloud quickstarts) python-pattern-saga-pattern-workflow
Java java-sandbox/design-patterns/saga/ (own pom.xml, Temporal SDK 1.41.1) java-pattern-saga-pattern-workflow

Each directory has a runner.json manifest, which the docs live runner will also use.

CI

  • run-design-patterns.yml gains Go, Python, and Java jobs. Each runs that language's design-pattern unit tests and then every manifest end to end.
  • The TypeScript job now also runs saga.test.ts, which nothing ran before.
  • The ci-on-pr.yml Java job's */*/pom.xml glob already compiles the new Java module.
  • run-design-pattern.sh exports TEMPORAL_ADDRESS=localhost:$port. The samples, including the TypeScript Worker, now load connection settings with envconfig, so a run on a non-default TEMPORAL_PORT reaches its own dev server instead of whatever is on 7233.

Testing

Run locally on macOS, with JDK 21 for Java:

  • Unit tests, 5 or 6 per language, covering success, failure at the last step, failure at a middle step, a failing compensation, and cancellation during the last step:
    • go test ./design-patterns/...
    • uv run pytest (Python)
    • mvn test (Java)
    • mocha saga.test.ts (TypeScript)
  • run-design-pattern.sh on all four manifests with TEMPORAL_PORT=7243: all PASS, status FAILED as expected, and the compensation lines in order.
  • go build ./... && go vet ./..., compileall, npx tsc --noEmit, and actionlint on the workflow.

A docs PR that syncs the page will follow as a draft until this merges.

Ports the Saga pattern from temporal-sa/temporal-design-patterns into
runnable, tested samples for Go, Python, and Java, matching the existing
TypeScript sample's request, Task Queue, log lines, and outcome. Each one
has a runner.json manifest and unit tests, and wraps its Workflow in
@@@SNIPSTART markers for the docs.temporal.io Saga pattern page.

All four Workflows now run compensations after cancellation (disconnected
context, CancelledError catch, detached scope, non-cancellable scope) and
keep compensating when one compensation fails, as the docs page's best
practices say. Tests cover success, failure at different steps, a failing
compensation, and cancellation.

run-design-patterns.yml gains Go, Python, and Java jobs that run the unit
tests and each manifest end to end, and the TypeScript job now runs the
Saga tests. The runner script exports TEMPORAL_ADDRESS so samples, which
now load envconfig, connect to the run's own dev server.
@Duncanma
Duncanma merged commit 3f696d1 into main Dec 3, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant