Durable Jobs
Best Practices
LiveShort rules for writing Durable Jobs that behave well in production.
Goal
Avoid the most common reliability mistakes.
Current status
Live
This area is documented as current, user-reliable behavior.
Workflow
- 1Use idempotency keys for every externally triggered job.
- 2Keep job handlers idempotent.
- 3Break workflows into named steps.
- 4Use correlation keys that identify the exact resource waiting for an event.
- 5Avoid long blocking work that should be an event wait or separate step.
Production checklist
- Use idempotency keys for API requests, webhooks, payments, signups, imports, and provisioning.
- Keep jobs idempotent even when StackShift is retrying for you.
- Wrap side effects in step.run with stable step names.
- Use correlation keys like user:user_123, order:order_123, or payment:pay_123.
- Use waitForEvent for external waiting instead of sleeping or polling inside a running process.
- Set explicit timeout behavior for waits.
- Use state for progress, counters, temporary markers, and locks.
- Watch the timeline before retrying manually.
Expected result
Your jobs are safer to retry, easier to observe, and easier to resume.