StepflowStepflow

Core Concepts

Understanding the key concepts in Stepflow

Core Concepts

Before diving deeper into Stepflow, it's helpful to understand the key concepts that make up the system.

Workflows

A workflow is a durable function that orchestrates a series of steps. Workflows are:

  • Durable: State is persisted, so workflows survive restarts
  • Resumable: If a workflow fails, it resumes from the last successful step
  • Type-safe: Full TypeScript support with inferred types
const workflow = createWorkflow(
  { id: "my-workflow" },
  async ({ step, sleep }) => {
    // Workflow logic here
  },
);

Steps

A step is an atomic unit of work within a workflow. Steps are:

  • Checkpointed: Results are saved, so steps never re-execute on retry
  • Idempotent: Safe to retry without side effects
  • Named: Each step has a unique name for tracking
const result = await step.run("process-order", async () => {
  return await processOrder(orderId);
});

Durable Sleep

Unlike regular setTimeout, Stepflow's sleep is durable:

  • Survives process restarts
  • Can span days, weeks, or months
  • Workflow resumes exactly when the sleep ends
await sleep("wait-3-days", "3d");

Events

Workflows can wait for external events with optional timeouts:

const payment = await waitForEvent("payment-received", {
  timeout: "1h",
});

Events are sent from outside the workflow:

await stepflow.notify(eventId, { status: "paid" });

Storage Adapters

Stepflow uses pluggable storage to persist workflow state:

AdapterBest For
MemoryDevelopment, testing
PostgreSQLProduction, ACID compliance
RedisHigh throughput, caching
SQLiteEdge deployments, Turso

Framework Adapters

Framework adapters expose Stepflow as HTTP endpoints:

  • Trigger workflows via REST API
  • Stream real-time updates via SSE
  • Integrate with any web framework

Client SDKs

Client SDKs make it easy to interact with Stepflow from your frontend:

  • TypeScript client for any environment
  • React hooks for web apps
  • React Native hooks for mobile apps

Execution Model

When a workflow runs:

  1. Trigger: Workflow is triggered with input data
  2. Execute: Steps run sequentially (or in parallel)
  3. Checkpoint: Each step result is saved
  4. Sleep/Wait: Workflow pauses for sleeps or events
  5. Resume: Workflow continues from where it left off
  6. Complete: Final result is returned
Trigger → Step 1 → Step 2 → Sleep → Step 3 → Complete

                         (persisted)

                    Process restarts...

                         Resume → Step 3 → Complete

Next Steps

  • Workflows - Deep dive into workflow definitions
  • Steps - Learn about step execution
  • Storage - Choose a storage adapter

On this page