Prompt
How do I make sure a workflow doesn't lose data between steps
Latest observation
Oct 16, 2026
OpenAI APIWeb search: off
To avoid losing data between workflow steps, the key is to make data transfer explicit, durable, and traceable. Here are the main practices that help:
1. Pass data explicitly between steps
- Don’t rely on hidden state or temporary variables.
- Each step should read from a clearly defined input and write a clearly defined output.
- Use structured payloads like JSON, not loosely typed blobs when possible.
2. Persist important state outside the workflow memory
- If a step might fail, restart, or run on another machine, store intermediate data in:
- a database
- object storage
- a queue/message broker
- workflow engine state storage
- Avoid keeping critical data only in RAM.
3. Make steps idempotent
- Design steps so rerunning them with the same input does not corrupt or duplicate data.
- This protects you from retries, crashes, and duplicate execution.
4. Use checkpoints
- Save progress after each important milestone.
- If the workflow restarts, resume from the last checkpoint instead of starting over.
5. Validate inputs and outputs at each step
- Confirm each step receives what it expects.
- Confirm it produced all required fields before the next step begins.
- Fail fast if data is missing or malformed.
6. Avoid overwriting without backup
- If one step transforms data, keep the original until the next step succeeds.
- Use versioned records or append-only logs when possible.
7. Handle retries carefully
- Retries can cause lost updates if state isn’t safely persisted.
- Use atomic writes, transactions, or compare-and-swap patterns where possible.
8. Log and trace the workflow
- Include correlation IDs or run IDs.
- Log inputs, outputs, and handoff points so you can reconstruct what happened.
9. Use transactional boundaries where needed
- If a step writes to a database, use transactions to ensure the write is complete or rolled back.
- For multi-system workflows, consider the outbox/inbox pattern or saga pattern.
10. Test failure scenarios
- Simulate crashes between steps.
- Restart the workflow mid-run and verify no data disappears.
- Test retries, duplicate messages, and partial failures.
If you want, I can also show:
- a generic workflow pattern for safe data handoff,
- a database-backed example,
- or guidance for a specific tool like Airflow, Temporal, n8n, Zapier, or LangGraph.