Idempotency Approaches
| Approach | When to Use | Key Generation |
|---|---|---|
| Auto-generated (default) | Context uniquely identifies operation | Hash of stepName + context |
Manual (.idempotencyKey()) | External system IDs, user-initiated retries, cross-service deduplication | Custom key (e.g., Stripe payment ID, request ID) |
Use Cases
| Scenario | Behavior | Example |
|---|---|---|
| Network retries | Second call with same key is ignored | Payment processing retry |
| Service restarts | Same key returns existing result | Service crashes mid-operation |
| Race conditions | Only first request succeeds | Multiple pods processing same order |
| Duplicate prevention | Prevents duplicate charges/operations | User clicks “Pay” twice |
Best Practices
- Use business identifiers (order ID, payment ID) when available
- Follow consistent naming patterns for key generation
- Ensure keys are unique within their scope
- Never reuse idempotency keys for different operations
Next Steps
Tracking Workflows
Learn how to record steps in workflows
Handling Failures
Handle retries and failures properly