Idempotency
Use idempotency when a retry or duplicate request should not repeat the underlying work. In Workflow, there are two common patterns: use the step ID for retry-safe external calls, and use hook tokens to coordinate duplicate workflow starts.
When to use this
- A step charges a payment, sends an email, enqueues work, or creates an external record.
- A route may receive duplicate requests that should map to one active workflow run.
Step idempotency
Every step has a unique, deterministic stepId available via getStepMetadata(). Pass this as the idempotency key to external APIs:
See Step Idempotency for why stepId is stable across retries and how to think about external API conflicts.
Run idempotency
For duplicate workflow-start requests, derive a hook token from your domain key. You can avoid obvious duplicate starts by checking whether an active hook already owns that token before calling start():
The workflow should create the deterministic hook and check await hook.getConflict() before duplicate-sensitive work: awaiting getConflict() suspends the workflow to commit the hook registration and resolves with the conflicting run when another active run already owns the token (or null once the hook is registered). See Run idempotency for the full pattern, including how to steer an active run with resumeHook() and how to handle the current race between start() and hook registration.
Key APIs
"use workflow": Declares the orchestrator function."use step": Declares step functions with full Node.js access.getStepMetadata(): Provides the deterministicstepIdfor idempotency keys.createHook(): Creates a hook with an optional deterministic token.getHookByToken(): Finds the hook that owns a token.resumeHook(): Resumes the active hook when the duplicate request carries data.start(): Starts a new workflow run.