Orchestration and choreography
A business workflow that spans several services (place an order: reserve stock, take payment, book a courier, confirm) needs coordination. Either one component directs the steps (orchestration), or each service reacts to the others' events and the workflow emerges (choreography). The choice decides who knows the state of an order, who handles failures, and how many places change when the workflow does. This module also covers the gateway and aggregation patterns that sit at the edge of most distributed systems.
1. The idea
| Orchestration | Choreography | |
|---|---|---|
| Who knows the workflow | The orchestrator, in one place | Nobody; it's spread across the services' event handlers |
| Workflow state | Held by the orchestrator: one query answers "where is order 81?" | Spread out; ask each service, or keep a separate tracker |
| Error handling | The orchestrator decides and compensates | Each service must listen for failure events and undo its own part |
| Coupling | Services know nothing of each other; the orchestrator knows them all | Services know the events they react to |
| Scale and responsiveness | The orchestrator can become a bottleneck | No central component; very scalable |
| Changing the workflow | One place | Several services' handlers |
A middle way is the front controller: choreography, but the first service in the flow also tracks the workflow's state by listening to every event, so status questions have one place to go.
At the edge: gateway and aggregation
- API gateway: one entry point for clients that handles authentication, rate limits, routing and protocol translation, so services don't each do it.
- Aggregation: a component (often the gateway or a backend-for-frontend) calls several services in parallel and combines their answers into one response, so a mobile app makes one call instead of six.
2. How it works
"Where is my order?" both ways
A gateway aggregating three services
The order page on a phone needs the order, its shipment and the customer's loyalty points. Watch the gateway gather them, including when one is slow.
3. Try it yourself
Design the failure path
An order workflow has four steps, each with a compensating step that undoes it. Choose the coordination style and which step fails, and read every message that follows, in order.
4. Trade-offs
Control vs scale
Orchestration gives one place for workflow logic, state and errors. Choreography removes the central component and its bottleneck, at the cost of workflow logic scattered across services.
Simple flows vs complex ones
Choreography shines for simple fan-out ("something happened, several react"). As steps, branches and compensations multiply, an orchestrator keeps the flow understandable.
Gateway features vs gateway logic
Cross-cutting features (auth, rate limits, routing) belong in a gateway. Business rules don't: a gateway full of logic becomes the ESB of Module 13.
Aggregate vs let clients call
Aggregation saves clients many round trips over slow mobile networks, and adds a component that must handle partial failures and timeouts sensibly.
5. In real projects
Use both. A common shape: an orchestrator for the core, failure-sensitive workflow (checkout, claims, onboarding), publishing events at the end that other services react to by choreography (analytics, loyalty, recommendations).
Workflow engines such as Temporal, Camunda, AWS Step Functions and similar tools provide durable orchestration: the workflow's state survives crashes, timers can wait for days, and each step's history is visible.
Model the workflow before choosing. Draw every step, its compensation and every failure branch. If the drawing is one straight line with no undo, choreography is fine; if it branches and compensates, an orchestrator will save you.
Say it in the interview
- "Orchestration or choreography?" Orchestration when the workflow has many steps, branches and compensations, or its state must be easy to query. Choreography for simple reactions where scale and decoupling matter more.
- "Who handles a failure in choreography?" Each service listens for failure events and undoes its own work. It works, but the overall error path is spread across services, so it needs careful design and tracing.
- "Why an API gateway?" One entry point for authentication, rate limiting and routing, and often aggregation so clients make one call. Business logic stays in services.
- Choreography for a long, compensating workflow, with no way to see an order's state.
- An orchestrator that also holds the business data of every service.
- A gateway aggregation that fails the whole page when one service is slow.
6. Remember it
How this hook works: what "conductor or dance floor" means
What the slogan means, phrase by phrase
- "Conductor"
- Orchestration: one component directs every step and knows where things stand.
- "dance floor"
- Choreography: everyone reacts to events; no one holds the whole picture.
Why this picture fits: it captures the trade-off in one image: control and visibility versus scale and independence.
The story → the concept
| Music | Workflow |
|---|---|
| The score | The workflow definition |
| Conductor stops and restarts a passage | Orchestrator compensates after a failure |
| Dancers reacting to each other | Services reacting to events |
| The doorman at the venue | The API gateway |
The trap it saves you from
Choosing choreography because it sounds more decoupled, then discovering nobody can tell where an order is.
7. Common mistakes
8. Design exercise (30 minutes)
- Model a workflow (10 min). Pick a multi-service workflow you know. List its steps and the compensation for each.
- Count the branches (10 min). How many ways can it fail? Who handles each today?
- Choose (10 min). Orchestration, choreography or a front controller? Write the decision with its trade-off in three sentences.
9. Self-check quiz
In orchestration, where is the workflow's state?
In choreography, how does a failure get compensated?
What is a front controller?
An aggregating gateway's loyalty-points call times out. What should it usually do?
Which belongs in an API gateway?
10. Go deeper
| Resource | Time | Why |
|---|---|---|
| Saga pattern (Chris Richardson) | 15 min | Orchestrated and choreographed sagas compared. |
| API gateway and backends for frontends | 10 min | The edge patterns, with their variations. |
| Temporal workflows | 20 min | How a durable workflow engine runs orchestration that survives crashes. |