Guides

Parent-Child Orchestration


Parent-child orchestration is a hierarchical pattern where a parent workflow spawns and manages one or more child workflows. Each child runs independently with its own execution context, state, and lifecycle, while the parent coordinates their overall behavior. This pattern lets you build complex systems from simple, reusable building blocks — different teams can own different child workflows, each child has isolated error handling, and you can run hundreds of children in parallel. Use parent-child orchestration when you need to break down complexity, coordinate multiple services, process items in parallel, or enable independent versioning of workflow components.

Parent Workflow
coordinates · aggregates · manages lifecycle
spawn children
Child A
validate
own journal
own retries
Child B
process
own journal
own retries
Child C
notify
own journal
own retries
collect results
Aggregate & Complete

Basic Parent-Child Communication

The simplest parent-child pattern spawns a child workflow, passes input data, and waits for the result. The parent calls start_child_workflow (or startChildWorkflow in TypeScript) with the child's name and input, receiving a handle that can be awaited for the child's return value. This decouples the parent from the child's internal implementation — the parent only needs to know the child's name and its input/output types.

1
use orcher::prelude::*;
2
use anyhow::Result;
3
use serde::{Deserialize, Serialize};
4
5
// Child workflow - validates an order
6
#[workflow(name = "validate_order", version = "1.0.0")]
7
pub async fn validate_order(
8
ctx: WorkflowContext,
9
order: OrderData,
10
) -> Result<ValidationResult> {
11
println!("Validating order {}", order.id);
12
13
// Validate customer
14
let customer = ctx.execute_task(check_customer, order.customer_id).await?;
15
16
// Validate inventory
17
let inventory = ctx.execute_task(check_inventory, order.items.clone()).await?;
18
19
// Validate pricing
20
let pricing = ctx.execute_task(check_pricing, order.total).await?;
21
22
Ok(ValidationResult {
23
valid: customer.valid && inventory.available && pricing.correct,
24
errors: vec![],
25
})
26
}
27
28
// Parent workflow - orchestrates order processing
29
#[workflow(name = "process_order", version = "1.0.0")]
30
pub async fn process_order(
31
ctx: WorkflowContext,
32
order: OrderData,
33
) -> Result<OrderResult> {
34
println!("Processing order {}", order.id);
35
36
// Start validation child workflow
37
let validation_handle = ctx
38
.start_child_workflow("validate_order", order.clone())
39
.await?;
40
41
println!("Validation workflow started: {}", validation_handle.id());
42
43
// Wait for validation result
44
let validation = validation_handle.result::<ValidationResult>().await?;
45
46
if !validation.valid {
47
return Ok(OrderResult::rejected(order.id, validation.errors));
48
}
49
50
// Continue with payment processing
51
let payment = ctx.execute_task(process_payment, order.total).await?;
52
53
Ok(OrderResult::success(order.id, payment.transaction_id))
54
}

Start the parent workflow:

1
use orcher::client::OrcherClient;
2
3
#[tokio::main]
4
async fn main() -> Result<()> {
5
let client = OrcherClient::new("localhost:50051").await?;
6
7
let order = OrderData {
8
id: "ord-123".to_string(),
9
customer_id: "cust-456".to_string(),
10
items: vec!["item-1".to_string(), "item-2".to_string()],
11
total: 99.99,
12
};
13
14
let handle = client
15
.start_workflow("process_order", "ord-123", order)
16
.await?;
17
18
println!("Order processing started: {}", handle.id());
19
20
let result = handle.result::<OrderResult>().await?;
21
println!("Order result: {:?}", result);
22
23
Ok(())
24
}

Next Steps