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):

async function myWorkflowFn() {
  // External API call directly in workflow - not checkpointed!
  const response = await fetch("https://api.example.com/data");
  return await response.json();
}
const myWorkflow = DBOS.registerWorkflow(myWorkflowFn);

Correct (external call in step using DBOS.runStep):

async function fetchData() {
  return await fetch("https://api.example.com/data").then(r => r.json());
}

async function myWorkflowFn() {
  const data = await DBOS.runStep(fetchData, { name: "fetchData" });
  return data;
}
const myWorkflow = DBOS.registerWorkflow(myWorkflowFn);

DBOS.runStep can also accept an inline arrow function:

async function myWorkflowFn() {
  const data = await DBOS.runStep(
    () => fetch("https://api.example.com/data").then(r => r.json()),
    { name: "fetchData" }
  );
  return data;
}

Alternatively, you can use DBOS.registerStep to pre-register a step or @DBOS.step() as a class decorator, but DBOS.runStep is preferred for most use cases.

Step requirements:

  • Inputs and outputs must be serializable to JSON
  • Cannot call, start, or enqueue workflows from within steps
  • Calling a step from another step makes the called step part of the calling step’s execution
  • DBOS must be launched before a step is called
  • Steps are only checkpointed when called from a workflow. As of DBOS 5.0, a step (runStep, registerStep, or @DBOS.step()) called outside a workflow runs as an ordinary function call, with no checkpoint, retries, or timeout
  • Only workflows can be started or enqueued; DBOS.startWorkflow on a step throws. To run a step durably on its own, wrap it in a workflow

When to use steps:

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

Reference: DBOS Steps