Course contentsShow
← Node.js
Lesson 1278 of 1,98011. Task Queues and Background ProcessingFree lesson

Orchestration over Infrastructure

Compare the merits of using specialized orchestration engines versus custom-coded Node.js state machines.

In this lesson, you will learn how to shift your architectural mindset from managing low-level message queues to designing declarative workflows that abstract away the underlying infrastructure.

The "Infrastructure" Trap

When building background processing systems in Node.js, it is easy to become obsessed with the "plumbing"—the specific Redis keys, polling intervals, or manual ack signals in your queueing library. If you find yourself writing if (error) { retryLogic(); } inside your worker functions, you are managing infrastructure, not workflows.

Orchestration: Defining Intent

"Orchestration over infrastructure" means treating the process as a first-class citizen separate from the workers. Instead of hard-coding state transitions, you define a workflow schema that tells a state machine what steps must happen, regardless of which worker node eventually executes them.

Consider a custom-coded Node.js state machine versus a dedicated orchestrator (like Temporal or a custom BPM engine). A custom implementation often looks like this:

// Managing Infrastructure (Manual state tracking)
async function processOrder(order) {
  await db.updateState(order.id, 'VALIDATING');
  try {
    await validate(order);
    await db.updateState(order.id, 'SHIPPING');
  } catch (err) {
    await db.updateState(order.id, 'FAILED'); // Manual cleanup
  }
}

By moving to orchestration, you stop writing the "how." You describe the workflow as a state machine where the framework handles the persistence, retries, and resume logic. Your code becomes a pure definition:

// Orchestration (Declarative intent)
async function orderWorkflow(order) {
  const result = await workflow.run('validate', order);
  if (result.success) {
    await workflow.run('ship', order);
  } else {
    await workflow.run('notifyFailure', order);
  }
}

Why Choose Orchestration?

When you write a custom state machine, you are responsible for handling partial failures, network partitions, and the "zombie" state problem. Specialized orchestrators provide "durability" for free: if the node running your process crashes, the orchestrator identifies exactly where it stopped and resumes from that specific state on a different worker. You stop coding around the infrastructure's limitations and start coding the business value.

Key Takeaway: Orchestration allows you to model business logic as an idealized, linear flow, delegating the messy realities of distributed failures and state persistence to a dedicated coordination layer.