Part 6 · 1 chapters · ~8 min

Durable Execution with Temporal

Workflows and activities, event histories and replay, determinism rules, durable timers and signals, retry policies and timeouts, sagas as workflows, versioning running workflows, Temporal's architecture, alternatives (AWS Step Functions, Restate, Inngest, DBOS), and when durable execution is worth it.

9

Code that survives crashes

code
// Temporal (TypeScript SDK): a cross-border transfer saga as a workflow
export async function crossBorderTransfer(t: Transfer): Promise<string> {
  const { debit, refund, bookFx, reverseFx, creditMpesa } = proxyActivities<Acts>({
    startToCloseTimeout: '30s', retry: { maximumAttempts: 8, backoffCoefficient: 2 } });
  const compensations: (() => Promise<void>)[] = [];
  try {
    await debit(t);            compensations.unshift(() => refund(t));
    const fx = await bookFx(t); compensations.unshift(() => reverseFx(fx));
    if (t.amountKobo > REVIEW_THRESHOLD) await condition(() => approved, '24h');   // wait for a human signal
    return await creditMpesa(t, fx);
  } catch (e) {
    for (const c of compensations) await c();                                        // compensate in reverse
    throw ApplicationFailure.nonRetryable('transfer failed and was refunded');
  }
}
optionmodel
Temporalcode-first workflows with replay; self-hosted or cloud
AWS Step FunctionsJSON/visual state machines, managed
Restate, DBOS, Inngestlighter durable execution embedded in services or the database
DURABLE EXECUTION WITH TEMPORAL
the workflow code looks sequential; its history survives crashes
workflow codeTemporal serveractivity workerschedule activity: debitWalletrun debitWallet (retries, timeouts)result → event history
swipe the figure sideways, or tap expand for full screen
1/4
workflows and activities
Workflow code describes the process as ordinary sequential code; activities do the side effects (calling a rail, writing a database) with retry and timeout policies.
workflow = logic; activities = side effectsretries and timeouts per activity