Course map

Topic 122 / Advanced

Workflow orchestration

Chapter 7.5 · Jobs, Workflows, Batch and Streams

What and why

A single background job (→ 121) handles one step; many real processes are several steps across services, each able to fail independently, needing the whole multi-step process to resume correctly rather than restart or get stuck. Workflow orchestration runs a long-lived, durable state machine (→ 46) that tracks which step a process instance is on, retries or compensates failed steps, and survives worker crashes by persisting progress — one visible coordinator, in contrast to pure event choreography (→ 113), where no component holds the whole picture. Builds on: → 121.

Diagram

orchestrator: reserve inventory → charge payment → schedule delivery
                                       │ fails
                                       ▼
                     run compensation for step 1: release inventory
                     (the Saga idea, → 139, whether run by an orchestrator or by choreography)

How it works

  1. A workflow definition lists the steps, and their compensations if a later step can fail, for a process instance.
  2. The orchestrator starts an instance, calls each step (often itself a background job or a service call), and durably persists which step completed before moving to the next — a crash mid-workflow resumes from the last persisted step, not from scratch.
  3. On a step failure, the orchestrator retries that step with backoff (→ 152) up to a limit, then either halts for manual intervention or runs compensating actions for already-completed steps.
  4. Because the orchestrator holds the whole process's state, it's the one place to look to answer "where is this order in its workflow" — the opposite of choreography, where that answer is scattered across every service's event handlers.
  5. Timeouts and human-in-the-loop waits ("wait up to 24 hours for approval") are native to a durable workflow engine, since it can sleep and resume without holding a process or thread open the whole time.

Practical example

(illustrative). A food-delivery order workflow (Project 15) runs: accept order → wait for restaurant acceptance (up to 2 minutes) → assign courier → track pickup → track delivery. If restaurant acceptance times out at 2 minutes, the orchestrator runs the "cancel and refund" compensation automatically, instead of the order sitting forever in an ambiguous, unowned "waiting" state.

When to use it

  • Use for multi-step, multi-service processes with meaningful intermediate states, timeouts, retries, and compensations that need one visible owner.
  • Avoid for simple, single-step background work (→ 121 is enough), or processes genuinely better modeled as independent services reacting to events with no need for a central view of progress — choreography stays simpler when there's no complex compensation logic.
  • Failure scenarios: running orchestration state only in memory in a stateless service — a crash loses track of which step an instance was on, re-running completed steps or abandoning the process; compensations that aren't themselves idempotent (→ 116) when a retry re-triggers them.
  • Simpler alternative: for a two- or three-step process with no compensation logic needed, a chain of background jobs ("on success, enqueue the next job") may be enough without a dedicated orchestration engine.

Practice

(process — fill the template on a small real system; 25–30 min, lab Kafka or Postgres for state). Design the workflow for Project 15's order flow as a state table: states, the step executed in each, the timeout (if any), and the compensation (if any) for every state that can fail after a prior state succeeded. Simulate one failure path by hand and trace exactly which compensations fire. Done when every state has a defined failure path and none is left with an undefined "then what."

Shared lab setup

Key takeaway

Orchestration gives one durable, visible coordinator for a multi-step process, trading some centralization for the ability to see and recover the whole flow. Done when you can: draw a workflow's states, timeouts, and compensations, and explain when choreography is simpler instead. Used next in → 139 (Saga formalizes the compensation side of this); Project 15.

References

None — this topic makes no external claims.

Source directory

Search the guide