Skip to main content

Continue-As-New

This page discusses Continue-As-New and how to decide when to use it.

What is Continue-As-New?

Continue-As-New allows you to checkpoint your Workflow's state and start a fresh Workflow.

There are two main reasons you might want to start a new Workflow:

  • A Workflow Execution with a long, or large Event History, such as one calling many Activities, may bog down and have performance issues. It could even generate more Events than allowed by the Event History limits.
  • A Workflow Execution can hit Workflow Versioning problems if it started running on an older version of your code and then begins executing on a newer version.

Your goal is to create a new Workflow with a fresh history that picks up where your last one left off. First, pass your latest relevant state into Continue-As-New. This hands it to a new Execution in the Execution Chain. This state is passed in as arguments to your Workflow. The parameters are typically optional and left unset by the original caller of the Workflow.

The new Workflow Execution has the same Workflow Id, but a different Run Id, and starts its own Event History.

You can repeat Continue-As-New as often as needed, which means that your Workflow can run forever. Workflows that do this are often called Entity Workflows because they represent durable objects, not just processes.

When in your Workflow is it right to Continue-As-New?

Temporal will tell your Workflow when it's approaching performance or scalability problems. Find out if it's time by checking Continue-As-New Suggested in your Workflow at spots in your implementation where you are ready to checkpoint your state.

To prevent long-running Workflows from running on stale versions of code, you may also want to Continue-as-New periodically, depending on how often you deploy. This makes sure you're running only a couple of versions, which avoids some backwards compatibility problems.