Building resilient distributed systems can feel daunting. Edge cases, unexpected errors, and sudden worker outages pose significant hurdles, making reliable applications seem difficult to achieve. Temporal’s Workflow management framework, coupled with AWS infrastructure, addresses these challenges by simplifying how developers build robust, fault-tolerant applications.

In a recent collaboration, Temporal and AWS showcased how developers can leverage Temporal’s TypeScript SDK to build and manage an e-commerce order fulfillment Workflow. The demo revealed how Temporal addresses common complexities through its capabilities: state management, error handling, signals, and Workflow monitoring.

Defining Clear Workflows

Temporal breaks down complex business processes — such as payment processing, inventory reservation, and order delivery — into clear, manageable steps. Each Workflow step is clearly visualized in Temporal’s web UI, including its input, output, and duration, making execution details transparent:

import { proxyActivities } from '@temporalio/workflow';

import type * as activities from '../src/activities';
import type { Order } from '../src/interfaces/order';

const { processPayment, reserveInventory, deliverOrder } = proxyActivities<typeof activities>({
  startToCloseTimeout: '5 seconds',
  retry: {
    nonRetryableErrorTypes: ['CreditCardExpiredException']
  }
});

export async function OrderFulfillWorkflow(order: Order): Promise<string> {
  const paymentResult = await processPayment(order);
  const inventoryResult = await reserveInventory(order);
  const deliveryResult = await deliverOrder(order);

  return `Order fulfilled: ${paymentResult}, ${inventoryResult}, ${deliveryResult}`;
}

Screenshot 2025-03-31 at 12.47.00 PM

Ensuring Continuity with Worker Failover

In distributed systems, workers can occasionally fail or become unavailable. Temporal seamlessly manages these situations by preserving Workflow state and ensuring continuous execution. If one worker stops unexpectedly, another automatically picks up exactly where the Workflow left off: Screenshot 2025-03-31 at 12.47.15 PM

Smart Error Handling and Retries

Temporal efficiently handles common error scenarios, such as intermittent API failures. Built-in retry mechanisms allow Workflows to automatically retry failed steps until they succeed, significantly reducing manual intervention and improving reliability:

export async function reserveInventory(order: Order): Promise<string> {
  // Simulate inventory service downtime
  // The activity will sleep the first 3 times it is called
  // And throw an error to simulate API call timeout
  const { attempt } = activity.Context.current().info;

  if (attempt <= 4) {
    console.log(`Inventory service down, attempt ${attempt}`);
    await new Promise((resolve) => setTimeout(resolve, 10000));
    throw new Error("Inventory service down");
  }

  // Simulate inventory reservation logic
  console.log("Reserving inventory...");
  await reserveInventoryAPI(order.items);

  await simulateDelay(1000);
  return `Inventory reserved for ${order.items.length} items`;
}

Not every error warrants a retry, however. Temporal recognizes non-retriable errors — such as processing payments with expired credit cards — and immediately halts execution. This approach prevents wasted resources and clearly identifies the precise reason for the Workflow failure.

Integrating Signals

Many real-world Workflows require human decisions, like order approvals. Temporal manages these scenarios through signal handlers. Workflows can pause, awaiting external input, and resume immediately once the required approval or other signal is received:

import {
  proxyActivities,
  defineSignal,
  setHandler,
  condition
} from '@temporalio/workflow';

import type * as activities from '../src/activities';
import type { Order } from '../src/interfaces/order';

const {
  requireApproval,
  processPayment,
  reserveInventory,
  deliverOrder
} = proxyActivities<typeof activities>({
  startToCloseTimeout: '5 seconds',
  retry: {
    nonRetryableErrorTypes: ['CreditCardExpiredException']
  }
});

export const approveOrder = defineSignal('approveOrder');

export async function OrderFulfillWorkflow(order: Order): Promise<string> {
  let isApproved = false;

  setHandler(approveOrder, () => {
    isApproved = true;
  });

  if (await requireApproval(order)) {
    await condition(() => isApproved);
  }

  const paymentResult = await processPayment(order);
  const inventoryResult = await reserveInventory(order);
  const deliveryResult = await deliverOrder(order);

  return `Order fulfilled: ${paymentResult}, ${inventoryResult}, ${deliveryResult}`;
}

To avoid indefinite waits, Temporal Workflows can incorporate timeouts. If a manual intervention isn’t received within a set timeframe, the Workflow gracefully times out, ensuring system resources aren’t wasted:

import {
  proxyActivities,
  defineSignal,
  setHandler,
  condition,
  sleep,
  ApplicationFailure
} from '@temporalio/workflow';

import type * as activities from '../src/activities';
import type { Order } from '../src/interfaces/order';

const {
  requireApproval,
  processPayment,
  reserveInventory,
  deliverOrder
} = proxyActivities<typeof activities>({
  startToCloseTimeout: '5 seconds',
  retry: {
    nonRetryableErrorTypes: ['CreditCardExpiredException']
  }
});

export const approveOrder = defineSignal('approveOrder');

export async function OrderFulfillWorkflow(order: Order): Promise<string> {
  let isApproved = false;

  setHandler(approveOrder, () => {
    isApproved = true;
  });

  if (await requireApproval(order)) {
    const approvalOrTimeout = Promise.race([
      condition(() => isApproved),
      sleep(30_000).then(() => {
        throw new ApplicationFailure('Approval timed out');
      })
    ]);

    await approvalOrTimeout;
  }

  const paymentResult = await processPayment(order);
  const inventoryResult = await reserveInventory(order);
  const deliveryResult = await deliverOrder(order);

  return `Order fulfilled: ${paymentResult}, ${inventoryResult}, ${deliveryResult}`;
}

For a deeper look into the TypeScript SDK demo, check out the original source code on GitHub.

Monitoring and Debugging Made Simple

Temporal provides a comprehensive web UI that simplifies monitoring Workflow execution. Developers can quickly identify execution steps, diagnose issues, and see exactly where Workflows succeeded or encountered problems. This transparency significantly streamlines debugging and increases reliability.


Temporal Cloud, hosted on AWS, equips developers with powerful tools to build resilient, distributed applications more easily and effectively. By simplifying state management, handling errors intelligently, managing manual interactions smoothly, and offering clear execution monitoring, Temporal reduces complexity and improves system reliability. Check out our extensive documentation to learn all about Temporal, and share your projects with our community via Code Exchange!

Whether you’re starting fresh or enhancing existing systems, Temporal offers a practical path to building reliable distributed applications. Get started today by claiming $1000 in Temporal Cloud credits.