| name | create-a-background-job |
| category | code |
| description | Create a durable background job with explicit delivery, idempotency, retry, cancellation, and recovery behavior. Use when work should continue outside a synchronous request. |
create-a-background-job
Move work off the request path without moving correctness, ownership, or evidence out of sight.
Procedure
- Define the job input, output, owner, business effect, deadline, ordering, and delivery guarantee.
- Put stable record identifiers in the queue payload and retrieve sensitive details through authorized storage.
- Make the handler idempotent and define its transaction or checkpoint boundaries.
- Acknowledge delivery only after durable progress makes replay safe.
- Set execution timeout, bounded exponential backoff, jitter, maximum attempts, and retry classification.
- Add cancellation and supersession checks before each expensive or irreversible step.
- Route exhausted or malformed work to a dead-letter path with owner, alert, and replay procedure.
- Bound concurrency and document per-key ordering or mutual-exclusion needs.
- Emit structured attempt, progress, outcome, latency, and queue-age signals.
- Test duplicates, crashes, poison input, dependency outage, cancellation, deploys, and replay.
- Reconcile source records, queue state, completed effects, and dead letters.
Guardrails
- Do not serialize credentials or full sensitive records into a queue message.
- Never retry every exception indefinitely.
- A successful dequeue is not evidence that the business effect completed.
Done
- The job contract and state transitions are documented
- Duplicate, crash, retry, cancellation, and replay tests are verified
- Source, queue, effect, and dead-letter records reconcile