Skip to main content
Reference vendor/dbos 1 min read

step-basics


title: Use Steps for External Operations impact: HIGH impactDescription: Steps enable recovery by checkpointing results tags: step, external, api, checkpoint

Use Steps for External Operations

Any function that performs complex operations, accesses external APIs, or has side effects should be a step. Step results are checkpointed, enabling workflow recovery.

Incorrect (external call in workflow):

import requests

@DBOS.workflow()
def my_workflow():
    # External API call directly in workflow - not checkpointed!
    response = requests.get("https://api.example.com/data")
    return response.json()

Correct (external call in step):

import requests

@DBOS.step()
def fetch_data():
    response = requests.get("https://api.example.com/data")
    return response.json()

@DBOS.workflow()
def my_workflow():
    # Step result is checkpointed for recovery
    data = fetch_data()
    return data

Step requirements:

  • Inputs and outputs must be serializable
  • Should not modify global state
  • Can be retried on failure (configurable)

When to use steps:

  • API calls to external services
  • File system operations
  • Random number generation
  • Getting current time
  • Any non-deterministic operation

Preemptible Async Steps

By default, cancelling (or timing out) a workflow interrupts it at the beginning of the next step — a step that is already executing first runs to completion. To cancel an executing async step immediately instead, mark it preemptible:

@DBOS.step(preemptible=True)
async def long_poll():
    # Cancelled immediately when the workflow is cancelled,
    # instead of running to completion
    return await poll_external_service()

preemptible=True is only supported for async (async def) steps.

Async Step Timeouts

Bound an async step that may hang with @DBOS.step(timeout_seconds=...); see step-retries for timeout and retry semantics.

Calling a step outside a workflow runs it as an ordinary function (no checkpoint, retries, or timeout).

Reference: DBOS Steps