|
| 1 | +--- |
| 2 | +id: unversioned-to-versioned-migration |
| 3 | +title: Migrating from Unversioned to Versioned Temporal Workers |
| 4 | +sidebar_label: Unversioned to versioned migration |
| 5 | +description: |
| 6 | + Implement Worker Versioning without the Temporal Worker Controller by deploying backward-compatible versioned Workers alongside existing ones and gradually shifting traffic before full migration. |
| 7 | +toc_max_heading_level: 4 |
| 8 | +keywords: |
| 9 | + - scaling |
| 10 | + - workers |
| 11 | + - versioning |
| 12 | + - deploys |
| 13 | +tags: |
| 14 | + - Temporal Service |
| 15 | + - Durable Execution |
| 16 | +--- |
| 17 | + |
| 18 | +This guide will help you implement Worker Versioning when the Temporal Worker Controller isn't used. If you are using the Temporal Worker Controller, follow [this guide](https://github.com/temporalio/temporal-worker-controller/blob/main/docs/migration-to-versioned.md). |
| 19 | + |
| 20 | +## Prerequisites |
| 21 | + |
| 22 | +- Unversioned Temporal Workers currently running in production |
| 23 | +- Temporal CLI >= 1.5.0 |
| 24 | +- Workers that connect to Temporal with Namespace and Task Queue configuration |
| 25 | + |
| 26 | +## Key steps |
| 27 | + |
| 28 | +- Ensure your versioned Worker code is backward-compatible with existing Workflow histories. |
| 29 | +- Deploy the versioned Worker. It won't receive Tasks until you activate it. |
| 30 | +- Use ramping to gradually shift traffic before full cutover. |
| 31 | +- Signal sleeping or idle Workflows to wake them up and migrate them to the versioned Worker. |
| 32 | +- Keep unversioned Workers running during the transition period. |
| 33 | +- Test thoroughly in a non-production environment before migrating production Workers. |
| 34 | + |
| 35 | +### Step 1: Update your Worker code |
| 36 | + |
| 37 | +Update your Worker initialization to include versioning configuration. |
| 38 | + |
| 39 | +**Before (Unversioned):** |
| 40 | + |
| 41 | +```go |
| 42 | +// Worker connects without versioning |
| 43 | +worker := worker.New(client, "my-task-queue", worker.Options{}) |
| 44 | +``` |
| 45 | + |
| 46 | +**After (Versioned):** |
| 47 | + |
| 48 | +```go |
| 49 | +buildID := os.Getenv("TEMPORAL_WORKER_BUILD_ID") |
| 50 | +deploymentName := os.Getenv("TEMPORAL_DEPLOYMENT_NAME") |
| 51 | +if buildID == "" || deploymentName == "" { |
| 52 | + // exit with an error |
| 53 | +} |
| 54 | + |
| 55 | +workerOptions := worker.Options{ |
| 56 | + DeploymentOptions: worker.DeploymentOptions{ |
| 57 | + UseVersioning: true, |
| 58 | + Version: worker.WorkerDeploymentVersion{ |
| 59 | + DeploymentName: deploymentName, |
| 60 | + BuildID: buildID, |
| 61 | + }, |
| 62 | + }, |
| 63 | +} |
| 64 | +worker := worker.New(client, "my-task-queue", workerOptions) |
| 65 | +``` |
| 66 | + |
| 67 | +:::info Important |
| 68 | + |
| 69 | +Your versioned Worker code must be fully backward-compatible with existing unversioned Workflow histories to avoid non-determinism errors. Don't make breaking Workflow code changes at this stage. |
| 70 | + |
| 71 | +::: |
| 72 | + |
| 73 | +### Step 2: Deploy your versioned Worker |
| 74 | + |
| 75 | +Deploy your versioned Worker alongside your existing unversioned Workers. The versioned Worker will begin polling but **won't receive any Tasks** until you explicitly activate it via the CLI. |
| 76 | + |
| 77 | +You can verify it's polling by inspecting the Worker Deployment: |
| 78 | + |
| 79 | +```shell |
| 80 | +temporal worker deployment describe --name "YourDeploymentName" |
| 81 | +``` |
| 82 | + |
| 83 | +### Step 3: Gradually ramp traffic (optional, but recommended) |
| 84 | + |
| 85 | +Instead of cutting over all at once, ramp a small percentage of new Workflow executions to the versioned Worker first: |
| 86 | + |
| 87 | +```shell |
| 88 | +temporal worker deployment set-ramping-version \ |
| 89 | + --deployment-name "YourDeploymentName" \ |
| 90 | + --build-id "YourBuildID" \ |
| 91 | + --percentage=5 |
| 92 | +``` |
| 93 | + |
| 94 | +Then monitor Workflows on the new version: |
| 95 | + |
| 96 | +```shell |
| 97 | +temporal workflow describe -w YourWorkflowID |
| 98 | +``` |
| 99 | + |
| 100 | +This returns versioning info such as: |
| 101 | + |
| 102 | +``` |
| 103 | +Versioning Info: |
| 104 | +
|
| 105 | + Behavior AutoUpgrade |
| 106 | + Version YourDeploymentName.YourBuildID |
| 107 | + OverrideBehavior Unspecified |
| 108 | +``` |
| 109 | + |
| 110 | +Increase the ramp percentage incrementally as you test and see that your Workflows are behaving as expected. |
| 111 | + |
| 112 | +### Step 4: Set the versioned Worker as Current |
| 113 | + |
| 114 | +Once validated, promote the versioned Worker to receive 100% of new Workflow executions: |
| 115 | + |
| 116 | +```shell |
| 117 | +temporal worker deployment set-current-version \ |
| 118 | + --deployment-name "YourDeploymentName" \ |
| 119 | + --build-id "YourBuildID" |
| 120 | +``` |
| 121 | + |
| 122 | +:::note |
| 123 | + |
| 124 | +Once a Current version is set, **unversioned Workers** will no longer receive any Tasks. Ensure your versioned Workers are healthy before this step. |
| 125 | + |
| 126 | +::: |
| 127 | + |
| 128 | +### Step 5: Migrate unversioned in-flight Workflows |
| 129 | + |
| 130 | +After setting the Current version, unversioned in-flight Workflows aren't dropped. On their next Task execution, they will automatically be routed to the versioned Worker. Once they are queued up on a versioned Worker, they will become either *Pinned* or *AutoUpgrade* depending on the Workflow's versioning behavior annotation. |
| 131 | + |
| 132 | +Sleeping or idle Workflows will not automatically begin to receive the new version information. If you have Workflows that are sleeping or waiting for an event, you must send them a Signal to wake them up so they can be dispatched to the versioned Worker on their next Task execution. |
| 133 | + |
| 134 | +To Signal all running Workflows at once: |
| 135 | + |
| 136 | +```shell |
| 137 | +temporal workflow signal \ |
| 138 | + --query "ExecutionStatus='Running'" \ |
| 139 | + --name "wake-up" \ |
| 140 | + --namespace production \ |
| 141 | + --rps 100 |
| 142 | +``` |
| 143 | + |
| 144 | +Once signaled, those Workflows will execute a Workflow Task and be routed to the Current versioned Worker. Keep your unversioned Workers running until all in-flight Workflows have migrated over. |
| 145 | + |
| 146 | +### Step 6: Scale down and clean up unversioned Workers |
| 147 | + |
| 148 | +Once you confirm that all Workflows are handled by versioned Workers, shut down |
| 149 | +your old unversioned Worker deployments. |
0 commit comments