# Workflow Versioning in Temporal

**URL:** <https://community.temporal.io/t/workflow-versioning-in-temporal/10384>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [December 14, 2023, 6:39am UTC](https://community.temporal.io/t/workflow-versioning-in-temporal/10384 "2023-12-14T06:39:51Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pushkala\_P](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pushkala_p/32/4429_2.png) [@Pushkala\_P](https://community.temporal.io/u/Pushkala_P)\
**Post date:** [December 14, 2023, 6:39am UTC](https://community.temporal.io/t/workflow-versioning-in-temporal/10384/1 "2023-12-14T06:39:51Z")

</div>

Hi Team,  
I am quite confused with the versioning.

```auto
int version = Workflow.getVersion(“updateAdded”, Workflow.DEFAULT_VERSION, 1);
if(version ==1) {
activities.updateRequest(requestDto);
}else {
activities.validateRequest(requestDto);
}

```

I have few workflow executions which were started already and waiting. Once I add this change and restart the worker, what I observe is both the already started executions and newly executions are picking the new branch against the condition for version=1.  
My requirement is already running execution should continue in older version of code and only newly created instances(after version change deployment) should pick up the new change. Is it possible to achieve this?

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [December 14, 2023, 9:24pm UTC](https://community.temporal.io/t/workflow-versioning-in-temporal/10384/2 "2023-12-14T21:24:43Z")

</div>

You can put the condition at the beginning of the workflow function and then use the same changeID in other places.

---

<div class="post-metadata">

**Author:** ![Pushkala\_P](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pushkala_p/32/4429_2.png) [@Pushkala\_P](https://community.temporal.io/u/Pushkala_P)\
**Post date:** [December 15, 2023, 5:18am UTC](https://community.temporal.io/t/workflow-versioning-in-temporal/10384/3 "2023-12-15T05:18:47Z")

</div>

hi @maxim  
Thanks for the response. I am a bit confused. But my question is I have a Workflow Definition as follows:

**A—\>B—\>C**

I have started a few executions already and they are currently at the execution point **A**. Now I made some changes in **B** with the versioning.  
What I observe is after restarting the worker, my executions which were halting at **A** are also picking up the new change with the latest version that I made in **B.** What I expect here is only the workflow instances that are started after deploying this change should pick up the new change and already running executions (which are halting at **A** ) should continue my older code itself.  
Is it possible to achieve this behavior with temporal versioning concept?

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [December 15, 2023, 5:20pm UTC](https://community.temporal.io/t/workflow-versioning-in-temporal/10384/4 "2023-12-15T17:20:04Z")

</div>

Yes.

```auto
getVersion("changeId1", ...) ...
A
getVersion("changeId1", ...) ...
B 
C

```

In the above sample, both getVersion calls will return the same value. So if A executed the old version B will execute the old one as well.

---

<div class="post-metadata">

**Author:** ![Pushkala\_P](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pushkala_p/32/4429_2.png) [@Pushkala\_P](https://community.temporal.io/u/Pushkala_P)\
**Post date:** [December 19, 2023, 7:35am UTC](https://community.temporal.io/t/workflow-versioning-in-temporal/10384/5 "2023-12-19T07:35:26Z")

</div>

hi @maxim  
When does actually the version increment occurs in temporal?

```auto
int version = Workflow.getVersion(“updateAdded”, Workflow.DEFAULT_VERSION, 1);
if(version ==1) {
activities.updateRequest(requestDto);
}else {
activities.validateRequest(requestDto);
}

```

Upon adding the above change, the change Id is updated with version 1. How does that change to version 2? Does temporal automatically update the version if we increase the maxSupported version value?

---

<div class="post-metadata">

**Author:** ![maxim](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/maxim/32/8_2.png) [@maxim](https://community.temporal.io/u/maxim)\
**Post date:** [December 19, 2023, 9:15pm UTC](https://community.temporal.io/t/workflow-versioning-in-temporal/10384/6 "2023-12-19T21:15:56Z")

</div>

The version is per workflow execution. So, each workflow can have a different value. The rule is that if getVersion is called during replay, it checks if there is a marker event with a version recorded. If recorded, then the version from the event is returned. If not recorded then the DEFAULT\_VERSION is returned. If the getVersion is called during new code execution, the maximum version is returned, and the marker command with that version is emitted.

All `getVersion` calls with the same `changeId` return the same value. It also means that all getVersion calls with the same changeId must be added simultaneously.

---

<div class="post-metadata">

**Author:** ![Pushkala\_P](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/pushkala_p/32/4429_2.png) [@Pushkala\_P](https://community.temporal.io/u/Pushkala_P)\
**Post date:** [December 20, 2023, 4:31am UTC](https://community.temporal.io/t/workflow-versioning-in-temporal/10384/7 "2023-12-20T04:31:57Z")

</div>

Thanks for the help @maxim
