Understand workflow versioning and replay errors
mainIn go-workflows, changing the logic of a workflow function (e.g., adding or removing an activity) without versioning will cause non-recoverable errors during history replay. This happens because the workflow engine attempts to match the new code logic against the existing event history, and a mismatch (like an unexpected ActivitySchedule event) triggers an error.
While other platforms like Cadence or Temporal use a workflow.Version(ctx) check to handle logic branches, go-workflows does not currently support built-in workflow versioning.
To avoid replay errors when updating workflow logic, use one of the following strategies:
- Side-by-side deployments: Run the new version of your workflow alongside the old version.
- Queue-based routing: Use different Queues to route specific workflow versions to specific workers.
// Example of what causes a replay error:
// If you change Workflow1 from version 1 to version 2 by adding Activity3,
// a running workflow that already completed Activity1 and is waiting for Activity2
// will fail because Activity3 is not in its recorded history.
func Workflow1(ctx workflow.Context) {
r1, _ := workflow.ExecuteActivity[int](ctx, workflow.DefaultActivityOptions, Activity1, 35, 12).Get(ctx)
log.Println("A1 result:", r1)
// Adding this line breaks existing workflows in replay:
r3, _ := workflow.ExecuteActivity(ctx, workflow.DefaultActivityOptions, Activity3).Get(ctx)
log.Println("A3 result:", r3)
r2, _ := workflow.ExecuteActivity[int](ctx, workflow.DefaultActivityOptions, Activity2).Get(ctx)
log.Println("A2 result:", r2)
}