Workflows
Workflows are durable functions that can contain multiple steps, make external API calls, query databases, and perform complex logic. If a workflow is interrupted (crash, deploy, server restart), it resumes from its last completed step.Steps
Steps are the building blocks of workflows. Each step is executed exactly once and its result is memoized. Steps let you break workflows into checkpoints.Workers
Workers are long-running processes that poll your database for pending workflows and execute them. Workers are stateless and can be started, stopped, and deployed independently. Your database is the source of truth. We recommend running workers via the CLI so workflow discovery stays in sync with youropenworkflow.config.{ts,js}:
You can run multiple workers simultaneously for high availability and
increased throughput.
How it Works
Understanding the execution flow helps when debugging or optimizing workflows:- Your app starts a workflow: A row is inserted into the
workflow_runstable with statuspending. - A worker picks it up: The worker polls the database, claims the workflow,
and sets its status to
running. - The worker executes steps: Each step is recorded in the
step_attemptstable. If a step succeeds, its result is cached. - The workflow completes: The worker updates the
workflow_runstatus tocompletedorfailed. - If the worker crashes: The workflow becomes visible to other workers via a heartbeat timeout. Another worker picks it up, loads the cached step results, and resumes from the next step.