Skip to main content

Application samples library

  • Polyglot application: Showcases how Workflow Executions, written in different languages, can send messages to each other. Go, Java, PHP, and TypeScript SDKs are represented in this sample. It also shows how to properly propagate errors, including how to do so across Workflows written in different languages.


  • Basic hello world: Simple example of a Workflow Definition and an Activity Definition.

API demonstrations#

  • Async activity completion: Example of an Expense reporting Workflow that communicates with a server API. Additional documentation: How to complete an Activity Execution asynchronously in Go

  • Retry Activity Execution: This samples executes an unreliable Activity. The Activity is executed with a custom Retry Policy. If the Activity Execution fails, the Server will schedule a retry based on the Retry Policy. This Activity also includes a Heartbeat, which enables it to resume from the Activity Execution's last reported progress when it retries.

  • Child Workflow: Demonstrates how to use execute a Child Workflow from a Parent Workflow Execution. A Child Workflow Execution only returns to the Parent Workflow Execution after completing its last Run.

  • Child Workflow with ContinueAsNew: Demonstrates that the call to Continue-As-New, by a Child Workflow Execution, is not visible to the a parent. The Parent Workflow Execution receives a notification only when a Child Workflow Execution completes, fails or times out. This is a useful feature when there is a need to process a large set of data. The child can iterate over the data set calling Continue-As-New periodically without polluting the parents' history.

  • Cancellation: Demonstrates how to cancel a Workflow Execution by calling CancelWorkflow, an how to defer an Activity Execution that "cleans up" after the Workflow Execution has been cancelled.

  • Coroutines: Do not use native go routines in Workflows. Instead use Temporal coroutines (workflow.Go()) to maintain a deterministic Workflow. Can be seen in the Split/Merge, DSL, Recovery, PSO, and Parallel Workflow examples.

  • Cron Workflow: Demonstrates a recurring Workflow Execution that occurs according to a cron schedule. This samples showcases the HasLastCompletionResult and GetLastCompletionResult APIs which are used to pass information between executions. Additional documentation: How to use the distributed cron feature.

  • Encrypted Payloads: How to customize encryption/decryption of Workflow data with the DataConverter API. Docs.

  • Crypt Converter: Advanced, newer example.

  • Query Example: Demonstrates how to Query the state of a single Workflow Execution using the QueryWorkflow and SetQueryHandler APIs. Additional documentation: How to Query a Workflow Execution in Go.

  • Selectors: Do not use the native Go select statement. Instead use Go SDK Selectors (selector.Select(ctx)) to maintain a deterministic Workflow. Can be seen in the Pick First, Mutex, DSL, and Timer examples.

  • Sessions: Demonstrates how to bind a set of Activity Executions to a specific Worker after the first Activity executes. This feature is showcased in the File Processing example. Addition documentation: How to use Sessions in Go.

  • Signals: Can be seen in the Recovery and Mutex examples. Additional documentation: eCommerce application tutorial, How to use Signals in Go.

  • Search Attributes: Demonstrates how to use custom Search Attributes that can be used to find Workflow Executions using predicates (must use with Elasticsearch).

  • Timer Futures: The sample starts a long running order processing operation and starts a Timer (workflow.NewTimer()). If the processing time is too long, a notification email is "sent" to the user regarding the delay (the execution does not cancel). If the operation finishes before the Timer fires, then the Timer is cancelled.

  • Tracing and Context Propagation: Demonstrates the client initialization with a context propagator, which propagates specific information in the context.Context object across the Workflow Execution. The context.Context object is populated with information prior to calling StartWorkflow. This example demonstrates that the information is available in the Workflow Execution and Activity Executions. Additional documentation: How to use tracing in Go.

  • Updatable Timer: Demonstrates timer cancellation and use of a Selector to wait on a Future and a Channel simultaneously.

  • Greetings: Demonstrates how to pass dependencies to activities defined as struct methods.

  • Greetings Local: Demonstrates how to pass dependencies to local activities defined as struct methods.

Dynamic Workflow logic examples#

These samples demonstrate some common control flow patterns using Temporal's Go SDK API.

  • Dynamic Execution: Demonstrates how to execute Workflows and Activities using a name rather than a strongly typed function.

  • Branching Acitivites: Executes multiple Activities in parallel. The number of branches is controlled by a parameter that is passed in at the start of the Workflow Execution.

  • Exclusive Choice: Demonstrates how to execute Activities based on a dynamic input.

  • Multi-Choice: Demonstrates how to execute multiple Activities in parallel based on a dynamic input.

  • Mutex Workflow: Demonstrates the ability to lock/unlock a particular resource within a particular Temporal Namespace. In this examples the other Workflow Executions within the same Namespace wait until a locked resource is unlocked. This shows how to avoid race conditions or parallel mutually exclusive operations on the same resource.

  • Parallel Workflow: This sample executes multiple branches in parallel using the workflow.Go() API.

  • Pick First: This sample executes Activities in parallel branches, picks the result of the branch that completes first, and then cancels other Activities that have not finished.

  • Split/Merge: Demonstrates how to use multiple Temporal coroutines, instead of native goroutines. This samples to processes chunks of a large work item in parallel, and then merges the intermediate results to generate the final result. Do not use native goroutines in Temporal Workflows. Instead, the coroutine provided by the workflow.Go API.

  • Synchronous Proxy Workflow pattern: This sample demonstrates a synchronous interaction with a "main" Workflow Execution from a "proxy" Workflow Execution. The proxy Workflow Execution sends a Signal to the "main" Workflow Execution, then blocks, waiting for a Signal in response.

Scenario based examples#

  • DSL Workflow: Demonstrates how to implement a DSL-based Workflow. This sample contains 2 yaml files that each define a custom "workflow" which instructs the Temporal Workflow. This is useful if you want to build in a "low code" layer.

  • Expense Request: This demonstrates how to process an expense request. This sample showcases how to complete an Activity Execution asynchronously.

  • File Processing: Demonstrates how to download and process a file using set of Activities that run on the same host. Activities are executed to download a file from the web, store it locally on the host, and then "process it". This samples showcases how to handle a scenario where all subsequent Activities need to execute on the same host as the first Activity in the sequence. In Go, this is achieved by using the Session APIs.

  • Particle Swarm Optimization: Demonstrates how to perform a long iterative math optimization process using particle swarm optimization (PSO). This sample showcases the use of parallel executions, ContinueAsNew for long histories, a Query API, and the use of a custom DataConverter for serialization.

  • Prometheus Metrics: Demonstrates how to instrument Temporal with Prometheus and Uber's Tally library.


Hello samples#

  • Hello: This sample includes a number of individual Workflows that can be executed independently. Each one demonstrates something specific.

Scenario-based samples#

  • File Processing Sample: Demonstrates how to route tasks to specific Workers. This sample has a set of Activities that download a file, processes it, and uploads the result to a destination. Any Worker can execute the first Activity. However, the second and third Activities must be executed on the same host as the first one.

  • Booking SAGA: Demonstrates Temporals take on the Camunda BPMN "trip booking" example.

  • Money Transfer: Demonstrates the use of a dedicated Activity Worker.

  • Money Batch: Demonstrates a situation where a single deposit should be initiated for multiple withdrawals. For example, a seller might want to be paid once per fixed number of transactions. This sample can be easily extended to perform a payment based on more complex criteria, such as at a specific time or an accumulated amount. The sample also demonstrates how to Signal the Workflow when it executes (Signal with start). If the Workflow is already executing, it just receives the Signal. If it is not executing, then the Workflow executes first, and then the Signal is delivered to it. Signal with start is a "lazy" way to execute Workflows when Signaling them.

  • Customer Application Approval DSL: Demonstrates execution of a customer application approval workflow defined in a DSL (like JSON or YAML)

API demonstrations#

  • Updatable Timer: Demonstrates the use of a helper class which relies on Workflow.await to implement a blocking sleep that can be updated at any moment.

  • Workflow Interceptor: Demonstrates how to create and register a simple Workflow Interceptor.

  • List Workflows: Demonstrates the use of custom search attributes and ListWorkflowExecutionsRequest with custom queries.

  • Payload Converter: Demonstrates the use of a custom payload converter.

  • Async Child Workflow: Demonstrates how to invoke a child workflow async, that can complete after parent workflow is already completed.

  • Terminate Workflow: Demonstrates how to terminate a workflow using client API.

  • Get Workflow Results Async: Demonstrates how to start and get workflow results in async manner.


Beginner samples#

The following samples demonstrate much of the basic functionality and capabilities of the SDK.

  • SimpleActivity: Single Activity Workflow

  • ActivityRetry: How to retry an Activity

  • AsyncActivity: How to call Activities asynchronously and wait for them using Promises

  • AsyncActivityCompletion: An asynchronous Activity implementation

  • AsyncClosure: How to run part of a Workflow asynchronously as a separate Task (coroutine)

  • CancellationScope: How to explicitly cancel parts of a Workflow

  • Child: Example of a child Workflow

  • Cron: A Workflow that is executed according to a cron schedule

  • Periodic: A Workflow that executes some logic periodically

  • Exception: Example of exception propagation and wrapping

  • PolymorphicActivity: Activities that extend a common interface

  • Query: Demonstrates how to Query the state of a single Workflow

  • Signal: Example of sending and handling a Signal

  • Saga: Example of SAGA pattern support

  • SearchAttributes: Example of Custom search attributes that can be used to find Workflows using predicates

Advanced samples#

The following samples demonstrate some of the more complex aspects associated with running Workflows with the SDK.

  • FileProcessing: Demonstrates Task routing features.

  • Booking SAGA: Demonstrates Temporal approach to a trip booking SAGA.

  • Money Transfer: Basic money transfer example.

  • MoneyBatch: Demonstrates a situation when a single deposit should be initiated for multiple withdrawals.

  • Updatable Timer: Demonstrates the use of a helper class which relies on Workflow.await to implement a blocking sleep that can be updated at any moment.

  • Subscription: Demonstrates a long-running process associated with a user ID. The process charges the user once every 30 days after a one month free trial period.