Tutorial: Order Processing (Python)
Build an order processing pipeline that validates orders, charges payment with retries, checks inventory in parallel, and finalizes the result — all with durable checkpointing.
from sayiir import Flow, run_durable_workflow, task
@taskdef validate_order(order: dict) -> dict: if order["amount"] <= 0: raise ValueError("Invalid amount") return {**order, "validated": True}
@task(timeout="30s", retries=3)def charge_payment(order: dict) -> dict: return {**order, "payment_id": "pay_123", "charged": True}
@taskdef check_inventory(order: dict) -> dict: return {**order, "in_stock": True}
@taskdef finalize(results: dict) -> str: payment = results["charge_payment"] inventory = results["check_inventory"] return f"Order complete: paid={payment['charged']}, stock={inventory['in_stock']}"
workflow = ( Flow("order-processing") .then(validate_order) .fork() .branch(charge_payment) .branch(check_inventory) .join(finalize) .build())
status = run_durable_workflow(workflow, "order-1", {"order_id": 1, "amount": 99.99})Demonstrates sequential tasks, fork/join parallelism, retries with timeouts, and durable execution. Swap InMemoryBackend for PostgresBackend to persist across restarts.
Full example: Order Processing (Python) Complete source code with instructions.
Next Steps
Section titled “Next Steps”- Retries & Timeouts — Fine-tune retry behavior
- Distributed Workers — Scale to multiple worker processes
- Signals — Add manual approval steps