step.run
step.run() makes one operation a durable step that Inngest can retry if it fails. Inngest saves a completed step's result, so later retries can continue without repeating that work.
They are useful when:
- You call an external API or write to a database.
- Later steps need the result of earlier work.
- You want to retry one failed operation without repeating completed steps.
Run two steps
This function loads a task, then processes it. The client import assumes you have created an Inngest client in ./client. Replace loadTask and processTaskRecord with your application's functions.
import { inngest } from "./client";
export const processTask = inngest.createFunction(
{ id: "process-task", triggers: { event: "app/task.created" } },
async ({ event, step }) => {
const task = await step.run("load-task", () =>
loadTask(event.data.taskId)
);
return step.run("process-task", () => processTaskRecord(task));
}
);
If process-task fails, Inngest retries that step. The completed load-task result stays saved, so the retry does not call loadTask again.
Retries and side effects
If the handler throws, Inngest retries this step according to the function's retries setting. Each step.run call has its own retry count. By default, a step gets one initial attempt and up to four retries. A completed earlier step keeps its saved result.
Put database writes and API calls inside step.run so a resumed function does not repeat completed work. A failed attempt can still have changed an external system before it threw or timed out. Use an idempotency key, an upsert, or another duplicate-safe operation for effects that a retry could repeat. Use a non-retriable error for a permanent failure; catch an exhausted step failure when the workflow can recover or compensate.
Results and limits
Inngest serializes returned values as JSON. Return only the data later work needs; for example, return a record ID instead of an entire record. Current platform limits are:
- 4 MiB step results
- 32 MiB total function run state
- 1,000 steps per function
- A step can run for up to two hours, subject to the hosting provider's shorter timeout
Next
step.runreference for every option.- Primitives for sleeps, waits, events, and invocations.
- Error handling and retries for failure and recovery patterns.
- Handling idempotency for duplicate-safe side effects.
- Limits for step and run limits.