DEV Community

Alex Spinov
Alex Spinov

Posted on

Temporal Has a Free API: Never Write Another Retry Loop or State Machine

Your payment flow has 7 steps, 3 retry policies, 2 timeout handlers, and a compensating transaction. Stop building that with if-else. Use Temporal.

What Is Temporal?

Temporal is a durable execution platform. You write workflows as normal code — Temporal makes them survive crashes, scale horizontally, and run for days/months/years.

// workflow.ts — this is durable. Crashes, restarts, deploys can't break it.
import { proxyActivities, sleep } from '@temporalio/workflow'

const { chargePayment, sendEmail, createShipment, updateInventory } = proxyActivities({
  startToCloseTimeout: '30s',
  retry: { maximumAttempts: 3 }
})

export async function orderWorkflow(order: Order): Promise<void> {
  // Step 1: Charge payment
  const paymentId = await chargePayment(order)

  // Step 2: Update inventory
  await updateInventory(order.items)

  // Step 3: Wait for warehouse confirmation (could be hours)
  await sleep('2 hours')

  // Step 4: Create shipment
  const trackingId = await createShipment(order, paymentId)

  // Step 5: Send confirmation email
  await sendEmail(order.customer, trackingId)
}
Enter fullscreen mode Exit fullscreen mode

If the server crashes between step 2 and step 3 — Temporal replays the workflow from step 3. No data loss. No duplicate charges.

Activities (Side Effects)

// activities.ts — these do the actual work
export async function chargePayment(order: Order): Promise<string> {
  const result = await stripe.paymentIntents.create({
    amount: order.total,
    currency: 'usd',
    customer: order.customerId
  })
  return result.id
}

export async function sendEmail(customer: Customer, trackingId: string) {
  await emailService.send({
    to: customer.email,
    subject: 'Your order has shipped!',
    body: \`Tracking: \${trackingId}\`
  })
}
Enter fullscreen mode Exit fullscreen mode

Why Temporal

  • Durable — workflows survive any failure (server crash, deploy, network partition)
  • Normal code — no state machines, no YAML, no DAGs. Just functions.
  • Long-running — workflows can run for months (subscription billing, user onboarding)
  • Visibility — see every workflow execution, its state, and history in the Temporal UI
  • Scalable — billions of concurrent workflows

Self-Hosted (Free)

temporal server start-dev
# Temporal server + UI at http://localhost:8233
Enter fullscreen mode Exit fullscreen mode

Building reliable distributed systems? Check out my developer tools or email spinov001@gmail.com.

Top comments (0)