﻿<head><script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4357510538660394"
     crossorigin="anonymous"></script></head>> ## Documentation Index
> Fetch the complete documentation index at: https://openworkflow.dev/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> ### When to use OpenWorkflow
>
> Use OpenWorkflow in TypeScript or JavaScript apps for:
>
> - Background jobs that need retries and must resume after a crash or deploy.
> - Multi-step integrations and data pipelines that need to save progress between operations.
> - AI workflows with multiple model or tool calls that need durable checkpoints.
> - Workflows that wait for a human approval, a webhook, or a timer before continuing.
>
> OpenWorkflow runs on Node.js 22.22+ or Bun, with PostgreSQL or SQLite storing workflow state. Your app enqueues runs, and a worker executes them.
>
> ### How to use OpenWorkflow
>
> Read and follow https://openworkflow.dev/skills/setup.md to set up OpenWorkflow.
>
> Define workflows with `defineWorkflow`, wrap operations in `step.run`, and enqueue runs with `ow.runWorkflow(workflow.spec, input)`. Start a worker with `npx @openworkflow/cli worker start` to execute them. See [Workflows](https://openworkflow.dev/docs/workflows.md), [Steps](https://openworkflow.dev/docs/steps.md), and [Signals](https://openworkflow.dev/docs/signals.md) for the APIs.

# Overview

> How OpenWorkflow works and how Workflows, Steps, and Workers fit together to save progress and recover after a crash

This page explains the mental model behind OpenWorkflow. For setup and command
examples, see [Quick Start](https://openworkflow.dev/docs/quickstart.md) and the linked detail pages.

## Building Blocks

OpenWorkflow has three core building blocks:

* **Workflows**: durable functions that describe your business process
* **Steps**: durable checkpoints that save results for reuse on replay
* **Workers**: stateless processes that execute and resume workflow runs

Your application enqueues workflow runs. Workers pick them up. The backend
(PostgreSQL or SQLite) stores durable state and coordinates recovery.

## Lifecycle

When a run starts:

1. Your app enqueues a run (for example, with `ow.runWorkflow(workflow.spec,
   input)`), creating a `pending` run in the database
2. A worker claims the run and marks it `running`
3. The worker replays workflow code from the beginning
4. Completed steps return cached outputs; new steps execute and persist results
5. The run transitions to `completed`, `failed`, or `canceled` (or stays
   `running` while durably parked for sleep)

Because replay is deterministic, crash recovery is reliable. A replacement
worker can continue from the last durable checkpoint without redoing completed
work.

## Why This Is Reliable

* **Memoized steps** replay durably recorded results without rerunning those
  step functions
* **Durable sleep** (`step.sleep`) pauses runs without holding worker capacity
* **Signals** (`step.sendSignal`, `step.waitForSignal`) enable runtime
  communication to & between workflows
* **Heartbeats + leases** (`availableAt`) allow automatic crash recovery
* **Database as source of truth** avoids a separate orchestration service

## Read Next

* [Workflows](https://openworkflow.dev/docs/workflows.md): define and run workflows, options, and states
* [Steps](https://openworkflow.dev/docs/steps.md): step types, naming, and retry behavior
* [Workers](https://openworkflow.dev/docs/workers.md): execution model, concurrency, and graceful shutdown
* [Configuration](https://openworkflow.dev/docs/configuration.md): config file and worker/backend settings


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.