Safe Workflow Versioning and Zero-Downtime Worker Deployments
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 Change | Replay Safe? | Why |
|---|---|---|
| Changing internal logic inside an Activity | Yes | Activities are not replayed once completed |
| Adding an optional field with default to Activity input | Yes | Existing serialized inputs deserialize cleanly |
Inserting a new Activity BEFORE an existing sleep | Breaking (needs patch) | Old history has TimerStarted where new code expects ActivityScheduled |
| Removing or reordering two Activities | Breaking (needs patch) | Command sequence diverges from recorded Event History |
Two Safe Evolution Mechanisms
- Inline Patching (
patched("my-change-id")): returnstruefor newly started workflows andfalsewhen replaying histories recorded before the patch marker existed. Once all pre-patch executions complete, you deprecate and remove the old branch cleanly. - 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.
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.