Workflow Orchestration
Orchestration is the practice of coordinating multiple tasks to achieve a higher-level business goal. This guide explains why Orchestrix is a great fit for this and how to structure your workflows.
Orchestration vs. Choreography
- Choreography: Each service works independently and reacts to events from others. It's decentralized but can be hard to track and debug.
- Orchestration: A central "orchestrator" (like Orchestrix) directs the flow of work, calling services and handling the logic. It's easier to reason about and provides a clear central definition of the process.
Designing Resilient Workflows
1. State Management
Use the FlowContext to keep track of progress. This is essential for compensation and for passing data between steps.
2. Side Effects
Try to isolate side effects into their own steps. Instead of one giant step that "Updates DB AND Sends Email", have two steps. This makes it easier to retry just the part that failed.
3. Idempotency
Ensure your orchestrator calls are idempotent. If Orchestrix retries a step that calls an external service, that service should handle the duplicate call gracefully.
Workflow Patterns
Sequential Execution
The simplest pattern. A -> B -> C.
flow
.step("A", taskA)
.step("B", taskB)
.step("C", taskC);Parallel Execution
When tasks are independent. (B and C) run after A.
flow
.step("A", taskA)
.parallel((p) => {
p.step("B", taskB);
p.step("C", taskC);
})
.step("D", taskD);Conditional Execution
Currently, conditional logic is handled inside step functions.
flow.step("conditional-step", async (ctx) => {
if (ctx.input.type === 'special') {
await doSpecialThing();
} else {
await doNormalThing();
}
});Why Orchestrix?
Orchestrix provides the perfect balance between power and simplicity for TypeScript developers. You get professional features like Sagas and Retries with a minimal, code-first API that lives right in your application.
Next Steps
- Explore Production Patterns for large-scale use.
- Learn about Observability to keep your flows healthy.