History Limits, Continue-As-New, and Child Workflows
The Limits
| Limit | Warning at | Hard limit | What happens at the hard limit |
|---|---|---|---|
| Events per workflow run | ~10,000 | ~51,200 | The server terminates the workflow |
| Total history size | 10 MB | 50 MB | The server terminates the workflow |
| One payload (input, result, or signal) | 256 KB | 2 MB | The request is rejected |
These are server settings, and some clusters change them. But treat them as fixed, because the reason behind them doesn't change: every workflow task replays the whole history.
A 40,000-event history means 40,000 events loaded and fed through your function every time anything happens. Raising the limit just gives you a slower, more expensive workflow.
Continue-As-New
Some workflows have no natural end: a subscription that renews every month, a workflow per device, a long polling loop. For these, you end the current run and start a new one with an empty history, in one step:
Here's the part that catches people out: nothing is carried over automatically. The new run starts with an empty history and only the inputs you give it. If you still need a local variable, you have to pass it in yourself. The upside is that this makes you be clear about what state your loop really needs.
// A subscription workflow that runs "forever" — 12 months per run.
func Subscription(ctx workflow.Context, s State) error {
for i := 0; i < 12; i++ {
workflow.Sleep(ctx, 30*24*time.Hour)
if err := workflow.ExecuteActivity(ctx, Charge, s).Get(ctx, nil); err != nil {
return err
}
s.MonthsBilled++
}
// Fresh history, same workflow ID, state passed forward by hand.
return workflow.NewContinueAsNewError(ctx, Subscription, s)
}Child Workflows — Another Way to Split Up History
A child workflow is a separate workflow, started by a parent, with its own history. However much the child does, the parent's history only gets a few events (initiated, started, completed). That fact tells you when to use one:
| Use a child workflow when… | Use an activity when… |
|---|---|
| The sub-task is a long process with many steps, and needs its own timers, signals, and retries | The sub-task is one piece of work |
| You're splitting work across hundreds of items, and their events would overflow the parent's history | There are only a few items, and their results are small |
| You want to query, cancel, or see the sub-task in the UI on its own | No one needs to see it separately |
The sub-task should keep running after the parent ends (set the parent-close policy to ABANDON) | It always ends inside the parent |
Child workflows aren't free, though. Each one is a full workflow with its own shard row, its own tasks, and its own replays. For splitting up lots of small pieces of work, an activity is much cheaper. A good rule of thumb: use a child workflow when the sub-task deserves its own page in the UI.
- Guarantees: Continue-as-new closes the old run and starts the new one in a single step, under the same workflow ID. So anyone who calls the workflow by its ID always reaches a live run.
- Does not guarantee: That anything carries over on its own. Local variables, waiting signals, and running activities don't move to the new run. Only what you pass in as input does.