Getting Started

Multi-Service Deployment with Parallel Fan-Out


When you need to coordinate the same operation across multiple services or regions, fan-out with child workflows lets you run them in parallel and roll back all successful deployments if any single one fails. This pattern is common for multi-region deployments, multi-provider notifications, and batch operations that span service boundaries.

How it works

Three phases: build once, deploy wide, verify everything. The distinctive part is the failure policy — this fan-out is all-or-nothing. A fleet running two different versions is worse than a failed deploy, so any region failing (at deploy or at health check) rolls back every region that succeeded.

All-or-Nothing Fan-Out
✓
build_packageOne artifact for every region
✓
deploy us-east-1Deployed — journaled
✓
deploy eu-west-1Deployed — journaled
✗
deploy ap-southeast-1Fails — retries exhausted
↺
rollback us-east-1 · eu-west-1Both compensated, in parallel
✗
workflow failsCleanly — every region on the old version
No region is left running a version the others don't have.

Example: deploying to three regions

1
import {
2
Workflow,
3
Tasks,
4
Task,
5
WorkflowContext,
6
createTaskRefs,
7
} from '@orcher/sdk';
8
9
@Tasks()
10
class DeployTasks {
11
@Task()
12
async buildPackage(config: AppConfig): Promise<string> {
13
return await ciClient.build(config);
14
}
15
16
@Task()
17
async deployToRegion(input: DeployInput): Promise<string> {
18
return await cloudClient.deploy(input.region, input.artifactId);
19
}
20
21
@Task()
22
async rollbackRegion(deploymentId: string): Promise<void> {
23
await cloudClient.rollback(deploymentId);
24
}
25
26
@Task()
27
async runHealthCheck(deploymentId: string): Promise<HealthStatus> {
28
return await cloudClient.healthCheck(deploymentId);
29
}
30
}
31
32
const tasks = createTaskRefs(DeployTasks);
33
34
@Workflow({ name: 'multi_region_deploy', version: '1.0.0' })
35
class MultiRegionDeploy {
36
async run(
37
ctx: WorkflowContext,
38
input: DeploymentInput,
39
): Promise<DeploymentResult> {
40
// Build the artifact once
41
const artifact = await ctx.executeTask(tasks.buildPackage, input.config);
42
43
// Deploy to all regions in parallel
44
const regions = ['us-east-1', 'eu-west-1', 'ap-southeast-1'];
45
const results = await Promise.allSettled(
46
regions.map((region) =>
47
ctx.executeTask(tasks.deployToRegion, { region, artifactId: artifact })
48
),
49
);
50
51
// Collect successes, check for failures
52
const deployments: Array<{ region: string; id: string }> = [];
53
let failed = false;
54
55
results.forEach((result, i) => {
56
if (result.status === 'fulfilled') {
57
deployments.push({ region: regions[i], id: result.value });
58
} else {
59
failed = true;
60
}
61
});
62
63
// Rollback all successful deployments if any failed
64
if (failed) {
65
await Promise.all(
66
deployments.map((d) => ctx.executeTask(tasks.rollbackRegion, d.id)),
67
);
68
throw new Error('Multi-region deployment failed');
69
}
70
71
// Health check all regions
72
for (const dep of deployments) {
73
const health = await ctx.executeTask(tasks.runHealthCheck, dep.id);
74
if (!health.isHealthy) {
75
await Promise.all(
76
deployments.map((d) => ctx.executeTask(tasks.rollbackRegion, d.id)),
77
);
78
throw new Error(`Health check failed in ${dep.region}`);
79
}
80
}
81
82
return { regions: deployments };
83
}
84
}

The fan-out pattern scales to any number of targets. Each parallel task is individually journaled, so if the process crashes after deploying to 2 of 3 regions, replay skips the completed deployments and continues with the remaining one.

Two fan-out failure policies

This is the same fan-out shape as parallel ETL with the opposite failure policy — choose by what a partial result means in your domain:

Isolate vs. All-or-Nothing
Isolate & continue
Partial success is success

Independent units — data sources, notifications, tenants. One failure is recorded and the rest deliver value. Parallel ETL works this way.

All-or-nothing
Partial success is a lie

Homogeneous targets that must agree — versions across regions, schema changes across shards. Any failure rolls back every success.

Ask: is the fleet allowed to disagree? If not, roll it all back.

Design notes

  • Deployed is not healthy. The deploy call succeeding only means the region accepted the artifact — the health-check phase is a second gate that can trigger the same full rollback. For a cheaper failure mode, verify one canary region before fanning out to the rest.
  • Roll back the set, not the stack. These compensations are independent, so they run in parallel — unlike a saga's ordered reverse walk, where each step's undo may depend on the next. Use ordering only when compensations actually depend on each other.
  • Rollback is durable too. Each rollback_region is a journaled task: a crash halfway through the rollback resumes it, exactly as in the saga's crash-mid-rollback walkthrough.
  • Promote regions to child workflows when deploys grow steps. Here each deploy is one atomic call, so plain tasks are right. When a per-region deploy becomes drain → deploy → warm → verify, give each region a child workflow with its own journal and failure boundary.

Next Steps