We use analytics cookies.We use cookies to analyze site traffic and improve your experience.
Loading...
System Design Masterclass · Messaging Event Systems
Free preview: the first 2 parts of this 7-part lesson.
Already bought the course? Sign in to read the whole lesson.
this lesson is part of
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design courseread the rest of this lesson in
System Design Masterclass
Unlock this lesson and the 751 other paid lessons
$25 once, by PayPal
See the System Design coursein Messaging Event Systems
This lesson is part of the full System Design Masterclass. Unlock it along with 769 other lessons for a one-time payment.
One-time payment by card or PayPal
Get Lifetime AccessOne-time payment: UPI, card or netbanking
Get Lifetime Access18 Foundation lessons are free, no payment needed. Try them now
A wedding involves dozens of vendors, caterer, florist, photographer, DJ, venue. Each works independently, but someone needs to coordinate the overall flow: book the venue first, then confirm the caterer based on venue capacity, then schedule the photographer based on the timeline, and if any vendor cancels, adjust the rest.
That coordinator is a process manager. In messaging systems, it's a component that tracks the state of a multi-step business process, sends commands to the right services at the right time, and handles the responses to decide what happens next.
Without a process manager, multi-step workflows become a tangled web of event handlers, each guessing what the others have done. With one, the workflow is explicit, traceable, and manageable.
Consider an order fulfillment flow: reserve inventory, charge payment, ship order, send confirmation. These steps must happen in sequence. If payment fails, inventory must be released. If shipping fails, payment must be refunded. A process manager tracks this state machine and ensures each step triggers the next, or the appropriate compensation if something goes wrong.
The process manager maintains a state machine for each process instance (e.g., each order):
States: [Created] → [InventoryReserved] → [PaymentCharged] → [Shipped] → [Completed]
↘ [InventoryFailed] ↘ [PaymentFailed] ↘ [ShipmentFailed]
↓ ↓ ↓
[Cancelled] [ReleasingInventory] [Refunding]
↓ ↓
[Cancelled] [Cancelled]
The process manager:
class OrderProcessManager {
async handle(event: DomainEvent, state: OrderState) {
switch (state.status) {
case 'created':
if (event.type === 'OrderPlaced') {
await commandBus.send(new ReserveInventory(event.orderId, event.items));
return { ...state, status: 'reserving_inventory' };
}
break;
case 'reserving_inventory':
if (event.type === 'InventoryReserved') {
await commandBus.send(new ChargePayment(event.orderId, state.amount));
return { ...state, status: 'charging_payment' };
}
if (event.type === 'InventoryFailed') {
return { ...state, status: 'cancelled', reason: 'out_of_stock' };
}
break;
// ... More states
}
}
}
Process manager vs. Choreography: In choreography, each service reacts to events independently, no central coordinator. In orchestration (process manager), a central component directs the flow. Choreography is simpler for straightforward flows. Process managers are essential for complex flows with conditional branches, timeouts, and compensating actions.
It is easy and good
“It is really nice and good Please join the course”