Мазмұнға өту
Мақала Kazakh тілінде әлі жарияланбаған. English нұсқасы көрсетілуде.

Durable Execution and Event-Driven Workflows: Systems Engineering Guide

2 мин оқу

Modern SaaS automation rarely fits inside a single 10-second HTTP request. Outbound campaigns fan out to thousands of recipients under provider rate limits, follow-up sequences sleep for hours waiting for a reply or payment event, and third-party APIs fail unpredictably.

Durable execution (pioneered by engines like Temporal) turns fragile cron-plus-queue glue code into deterministic, crash-proof stateful workflows that survive deploys, restarts, and outages cleanly.

Cron + Ad-Hoc Queues vs Durable Execution

DimensionCron Polling + Ad-Hoc Job QueuesDurable Execution Workflows
Multi-step stateScattered across DB status columns and partial flagsSingle readable function with persisted event history
Long timers (hours/days)Polled DB tables with clock drift and lock contentionNative durable timers waking on exact schedule
Crash recoveryManual cleanup scripts and duplicate side effectsDeterministic replay resumes at exact pending step
External events (replies/payments)Complex webhook state-machine joinsTyped Signals delivered directly to running workflow ID
ObservabilityPiecing together scattered worker logsComplete per-execution timeline with inputs, retries, and stack traces

Conceptual Durable Follow-Up Workflow

ts
export async function followUpSequenceWorkflow(input: {
  recipientId: string;
  waitMs: number;
}): Promise<"converted" | "replied" | "reminded" | "cancelled"> {
  let replied = false;
  let paid = false;

  setHandler(customerRepliedSignal, () => {
    replied = true;
  });
  setHandler(paymentConfirmedSignal, () => {
    paid = true;
  });

  await sendInitialMessageActivity(input.recipientId);

  const eventArrived = await condition(() => replied || paid, input.waitMs);
  if (paid) return "converted";
  if (replied) return "replied";
  if (!eventArrived) {
    await sendReminderActivity(input.recipientId);
    return "reminded";
  }
  return "cancelled";
}

Curriculum: All Articles in This Track

Осы бөлімде

Бұл пайдалы болды ма?