Skip to content

Safe Workflow Versioning and Zero-Downtime Worker Deployments

2 min read

In stateless web apps, deploying new code is easy: spin up new containers, drain old HTTP requests in 30 seconds, and terminate old containers. In durable workflow systems, executions may have been sleeping for 7 days on an older code path. Changing the sequence of activities or timers carelessly breaks deterministic replay for every in-flight workflow.

Safe vs Breaking Workflow Changes

Code ChangeReplay Safe?Why
Changing internal logic inside an ActivityYesActivities are not replayed once completed
Adding an optional field with default to Activity inputYesExisting serialized inputs deserialize cleanly
Inserting a new Activity BEFORE an existing sleepBreaking (needs patch)Old history has TimerStarted where new code expects ActivityScheduled
Removing or reordering two ActivitiesBreaking (needs patch)Command sequence diverges from recorded Event History

Two Safe Evolution Mechanisms

  1. Inline Patching (patched("my-change-id")): returns true for newly started workflows and false when replaying histories recorded before the patch marker existed. Once all pre-patch executions complete, you deprecate and remove the old branch cleanly.
  2. Worker Build-ID Versioning: pins each running workflow execution to the worker build version that started it, while new executions automatically route to the latest worker version.
ts
export async function campaignFollowUpWorkflow(input: FollowUpInput): Promise<void> {
  await sendFirstTouchActivity(input);

  if (patched("add-quiet-hours-check-v2")) {
    const safeDelayMs = await computeQuietAwareDelayActivity(input.recipientId, input.delayMs);
    await sleep(safeDelayMs);
  } else {
    await sleep(input.delayMs);
  }

  await sendFollowUpActivity(input);
}

Mandatory CI Replay Tests

Export anonymized JSON Event Histories from real production executions (covering every active workflow type) and run a deterministic replay test suite in CI on every PR. If a refactor accidentally alters command ordering, CI fails in 3 seconds before a single production worker ever restarts.

Next: ingest external platform events reliably without dropping webhooks in Production Webhook Pipelines.

Was this helpful?