Skip to main content

Introduction to Workflows

Temporal Workflows orchestrate your Activities.

They are resilient - they can run and keep running for years, even if the underlying infrastructure fails. If the application itself crashes, Temporal will automatically recreate its Workflow’s pre-failure state so it can continue right where it left off.

In our reimbursement example, if the network fails right after the withdrawal but before the deposit, Temporal recreates the Workflow Execution from its last known state and continues as if no failure ever occurred.

This Workflow orchestrates our two Activities.

import (
"go.temporal.io/sdk/temporal"
"go.temporal.io/sdk/workflow"
)

func ReimbursementWorkflow(ctx workflow.Context, userId string, amount float64) (string, error) {
var withdrawSuccess bool
err := workflow.ExecuteActivity(ctx, WithdrawMoney, amount).Get(ctx, &withdrawSuccess)

var depositSuccess bool
err = workflow.ExecuteActivity(ctx, DepositMoney, amount).Get(ctx, &depositSuccess)

return fmt.Sprintf("reimbursement to %s successfully complete", userId), nil
}
4 / 9