0

What is Replay in Cadence/Temporal workflow? Is it the same as "retry"?

Why can't I simply use my own logger in workflow code due to replay?

Sharan Foga
  • 135
  • 8
Long Quanzheng
  • 2,076
  • 1
  • 10
  • 22

1 Answers1

1

“Retry” and "replay" are completely different.

Replay is for rebuilding the workflow thread states(process/thread stack).

Imagine this workflow code(in Java):

 activityStub.doA()
 LOG.info("first log")
 activityStub.doB()
 LOG.info("second log")

If LOG is not from Workflow.getLogger or not wrapped by Workflow.isReplay, the first log will be printed more than one times — just depend on how many times the code got replayed.

The timeline of causing duplicated logs:

  • After doA is completed, first log is printed.
  • And then doB is executed, let say doB will take 1 minute.
  • During the 1 minute, the worker crashes or got restarted.
  • And then the doB completed.
  • Then there will be a new workflow task to process the completion of doB.
  • The workflow task will then executed in a new worker host, which requires a replay to rebuild the Stack until the code of doB. During the replay, assuming LOG is your own logger without wrapping by workflow.isReplay(), the first log will be printed again.
  • And then doB will get completed and then the second log will be printed.

So at the end, you will see the logs:

first log
first log
second log

Long Quanzheng
  • 2,076
  • 1
  • 10
  • 22