DEV Community

Alex Spinov
Alex Spinov

Posted on

Temporal Has a Free API That Makes Your Code Failure-Proof

Temporal is the durable execution platform that guarantees your code runs to completion — even through crashes, network failures, and server restarts.

What Is Temporal?

Temporal is an open-source runtime for building reliable distributed systems. Write your business logic as normal code, and Temporal handles retries, state persistence, and failure recovery automatically.

Core Concept: Workflows

A Temporal workflow is a function that survives anything:

import { proxyActivities, sleep } from '@temporalio/workflow'

const { sendEmail, chargeCard, fulfillOrder, notifyWarehouse } = proxyActivities({
  startToCloseTimeout: '30s',
  retry: { maximumAttempts: 5 }
})

export async function orderWorkflow(order: Order): Promise<string> {
  // Step 1: Charge card (retries automatically on failure)
  const paymentId = await chargeCard(order.customerId, order.total)

  // Step 2: Send confirmation
  await sendEmail(order.email, `Order ${order.id} confirmed!`)

  // Step 3: Wait for warehouse (survives server restarts)
  await notifyWarehouse(order.items)

  // Step 4: Wait 30 days for return window
  await sleep('30 days') // Yes, 30 DAYS. Temporal persists this.

  // Step 5: Close order
  return `Order ${order.id} completed`
}
Enter fullscreen mode Exit fullscreen mode

If the server crashes at step 3, Temporal resumes from step 3 — not from the beginning.

Activities (Side Effects)

export async function chargeCard(customerId: string, amount: number): Promise<string> {
  const response = await stripe.paymentIntents.create({
    customer: customerId,
    amount: Math.round(amount * 100),
    currency: 'usd',
  })
  return response.id
}

export async function sendEmail(to: string, body: string): Promise<void> {
  await resend.emails.send({ from: 'orders@myapp.com', to, subject: 'Order Update', text: body })
}
Enter fullscreen mode Exit fullscreen mode

Start Workflows

import { Client } from '@temporalio/client'

const client = new Client()

// Start workflow
const handle = await client.workflow.start(orderWorkflow, {
  taskQueue: 'orders',
  workflowId: `order-${orderId}`,
  args: [orderData],
})

// Query status
const status = await handle.query('getStatus')

// Signal workflow (external events)
await handle.signal('cancelOrder', { reason: 'Customer request' })
Enter fullscreen mode Exit fullscreen mode

REST API

# List workflows
curl -s 'http://localhost:8233/api/v1/namespaces/default/workflows' | jq '.executions | length'

# Get workflow status
curl -s 'http://localhost:8233/api/v1/namespaces/default/workflows/order-123' | jq '.status'
Enter fullscreen mode Exit fullscreen mode

Use Cases

  • Order processing: multi-step transactions that must complete
  • User onboarding: drip emails over days/weeks
  • Data pipelines: ETL that retries on failure
  • Subscription billing: recurring charges with grace periods
  • CI/CD: deployment pipelines with rollback

Getting Started

# Local development server
npx @temporalio/create@latest my-project
cd my-project && npm run start.watch

# Or Docker
docker compose up temporal
Enter fullscreen mode Exit fullscreen mode

Building reliable scraping pipelines? Scrapfly + Temporal = bulletproof data extraction. Email spinov001@gmail.com for durable scraping solutions.

Top comments (0)