2

"Does cadence have a concept of ""workflow evolution""?

In other words, I have a ""stateful actor"" that models a customer. Initially, the customer has two fields with some signal methods that modify them, some query methods that fetch state, and some main workflow on that actor. Suppose I have 10 of these instances and they are long-lived.

Later I want to add a third field and maybe another signal method. What can I use?

Maxim Fateev
  • 6,458
  • 3
  • 20
  • 35
Sharan Foga
  • 135
  • 8
  • I had another post for this versioning concept: https://stackoverflow.com/questions/65007136/uber-cadence-workflow-versioning/65029001#65029001 – Long Quanzheng May 06 '22 at 23:18

2 Answers2

1

Versioning with Cadence can help here. Here's the documentation.

From the documentation, as an example, a line like below

err := workflow.ExecuteActivity(ctx, ActivityA, data).Get(ctx, &result1)

becomes

var err error
v := workflow.GetVersion(ctx, "Step1", workflow.DefaultVersion, 1)
if v == workflow.DefaultVersion {
    err = workflow.ExecuteActivity(ctx, ActivityA, data).Get(ctx, &result1)
} else {
    err = workflow.ExecuteActivity(ctx, ActivityC, data).Get(ctx, &result1)
}

if you have more than 2 versions it will look like below:

v := workflow.GetVersion(ctx, "Step1", workflow.DefaultVersion, 2)
if v == workflow.DefaultVersion {
    err = workflow.ExecuteActivity(ctx, ActivityA, data).Get(ctx, &result1)
} else if v == 1 {
    err = workflow.ExecuteActivity(ctx, ActivityC, data).Get(ctx, &result1)
} else {
    err = workflow.ExecuteActivity(ctx, ActivityD, data).Get(ctx, &result1)
}

and so on. You can refer to the documentation for more details.

Ender
  • 176
  • 1
  • 6
0

Yes, Cadence and Temporal support the evolution of already running workflows. See Versioning documentation for more details.

Maxim Fateev
  • 6,458
  • 3
  • 20
  • 35