Choreography-Based Coordination

orchestrationHard
Applicability

When to Use

When you want to avoid a single point of failure
When services should be independently deployable
When the workflow may evolve frequently
Overview

How It Works

Unlike orchestration where a central agent directs the workflow, choreography lets each MCP server react to events independently. When one server completes its work, it emits an event that others react to. There is no central coordinator. This pattern uses a message broker (Kafka or NATS MCP Server) for event distribution. Each service subscribes to relevant events and publishes its own. The workflow emerges from the interactions rather than being defined in a single place.
Implementation

Code Example

typescript
// Order Service
async function onOrderCreated(order) {
  await kafka.produce({ topic: "order.created", messages: [{ value: JSON.stringify(order) }] });
}

// Payment Service (reacts to order.created)
kafka.consume("order.created", async (msg) => {
  const order = JSON.parse(msg.value);
  const payment = await stripe.createCharge({ amount: order.total });
  await kafka.produce({ topic: "payment.completed", messages: [{ value: JSON.stringify({ orderId: order.id, paymentId: payment.id }) }] });
});

// Shipping Service (reacts to payment.completed)
kafka.consume("payment.completed", async (msg) => {
  const { orderId } = JSON.parse(msg.value);
  const label = await createShippingLabel(orderId);
  await kafka.produce({ topic: "shipment.created", messages: [{ value: JSON.stringify({ orderId, trackingNumber: label.tracking }) }] });
});

Quick Info

Categoryorchestration
ComplexityHard

Need Architecture Help?

Our team designs custom automation architectures.

Get in Touch
CortexAgent Customer Service

Want to skip the form?

Our team is available to help you get started with CortexAgent.

This chat may be recorded for quality assurance. You can view our Privacy Policy.