DEV Community

Alex Spinov
Alex Spinov

Posted on

Temporal Has a Free API — Durable Workflow Execution for Any Language

TL;DR

Temporal is an open-source durable execution platform that makes your code fault-tolerant by default. Write normal functions — Temporal handles retries, timeouts, and crash recovery automatically. Free to self-host or use Temporal Cloud's free tier.

What Is Temporal?

Temporal solves the hardest distributed systems problem — reliability:

  • Durable execution — your code survives crashes, restarts, deployments
  • Automatic retries — configurable retry policies for every activity
  • Long-running workflows — run for seconds, hours, or years
  • Multi-language — Go, Java, TypeScript, Python, .NET, PHP
  • Visibility — see every workflow's state in the UI
  • Free — MIT license, or Temporal Cloud free tier

Quick Start (TypeScript)

npm install @temporalio/client @temporalio/worker @temporalio/workflow @temporalio/activity
Enter fullscreen mode Exit fullscreen mode

Define Activities (unreliable operations)

// src/activities.ts
export async function sendEmail(to: string, subject: string): Promise<void> {
  // If this fails, Temporal retries it automatically
  await emailService.send({ to, subject });
}

export async function chargePayment(userId: string, amount: number): Promise<string> {
  const result = await paymentGateway.charge(userId, amount);
  return result.transactionId;
}

export async function shipOrder(orderId: string): Promise<void> {
  await fulfillmentService.ship(orderId);
}
Enter fullscreen mode Exit fullscreen mode

Define Workflow (orchestration logic)

// src/workflows.ts
import { proxyActivities, sleep } from "@temporalio/workflow";
import type * as activities from "./activities";

const { sendEmail, chargePayment, shipOrder } = proxyActivities<typeof activities>({
  startToCloseTimeout: "30 seconds",
  retry: { maximumAttempts: 5 },
});

export async function orderWorkflow(userId: string, orderId: string, amount: number): Promise<string> {
  // Step 1: Charge payment
  const txId = await chargePayment(userId, amount);

  // Step 2: Ship order
  await shipOrder(orderId);

  // Step 3: Send confirmation
  await sendEmail(userId, `Order ${orderId} shipped! Transaction: ${txId}`);

  // Step 4: Wait 7 days, then send review request
  await sleep("7 days");
  await sendEmail(userId, "How was your order? Leave a review!");

  return txId;
}
Enter fullscreen mode Exit fullscreen mode

Start the Worker

// src/worker.ts
import { Worker } from "@temporalio/worker";
import * as activities from "./activities";

async function run() {
  const worker = await Worker.create({
    workflowsPath: require.resolve("./workflows"),
    activities,
    taskQueue: "orders",
  });
  await worker.run();
}

run();
Enter fullscreen mode Exit fullscreen mode

Start a Workflow

// src/client.ts
import { Client } from "@temporalio/client";
import { orderWorkflow } from "./workflows";

const client = new Client();

const handle = await client.workflow.start(orderWorkflow, {
  taskQueue: "orders",
  workflowId: `order-${orderId}`,
  args: [userId, orderId, 99.99],
});

console.log(`Started workflow: ${handle.workflowId}`);
const result = await handle.result();
console.log(`Completed with txId: ${result}`);
Enter fullscreen mode Exit fullscreen mode

Temporal vs Alternatives

Feature Temporal Bull/BullMQ AWS Step Functions Inngest
Price Free (self-host) Free Pay per transition Free tier
Languages 6+ Node.js JSON/ASL TypeScript
Durability Full Redis-based Full Full
Long workflows Years Hours 1 year Days
Local dev Full server Redis needed SAM Local Dev server
Versioning Built-in Manual Versions Built-in

Use Cases

  1. Order processing — payment, fulfillment, notifications
  2. User onboarding — multi-step flows over days/weeks
  3. Data pipelines — ETL with automatic retry
  4. Subscription billing — recurring workflows
  5. CI/CD orchestration — complex deployment pipelines
  6. Saga pattern — distributed transactions with compensation

Resources


Building durable data pipelines? My Apify scraping tools extract web data reliably — orchestrate them with Temporal for fault-tolerant data workflows. Questions? Email spinov001@gmail.com

Top comments (0)