Rust Idempotent Workflows
Use this skill to make Rust workflows reliable when clients retry, workers
crash, requests race, and external side effects cannot be rolled back.
Core Workflow
- Write the failure story before writing code. List what happens if the process
crashes after each database write and after each external side effect.
- Identify the idempotency boundary: HTTP endpoint, command handler, queue job,
webhook, or external callback.
- Choose the idempotency strategy:
- Natural idempotency from a unique business key.
- Client-provided idempotency key with save-and-replay.
- Server-generated deduplication key.
- Outbox or queue table for side effects.
- Put state transitions and idempotency records in the same transaction when
they must agree.
- Make duplicate concurrent requests deterministic. Use unique constraints,
locks, serializable transactions, or explicit conflict handling.
- Treat external side effects as at-least-once unless the provider guarantees
more. Store enough state to retry or reconcile.
- Add tests for duplicate requests, retry after timeout, concurrent requests,
crash windows when practical, and worker retry behavior.
Idempotency Key Rules
Read references/idempotency.md before adding idempotency keys or save-and-
replay behavior.
- Bind the key to the authenticated user or tenant.
- Store a hash of the request payload when replaying responses.
- Return the original response for exact replays.
- Reject reuse of the same key with a different payload.
- Expire records only after product and provider retry windows have passed.
Background Work Rules
Read references/background-workers.md when adding queue tables, polling
workers, retries, or external side effects.
- Commit durable intent before sending external effects.
- Use
pending, in_progress, succeeded, and failed states deliberately.
- Keep retry counts, next-attempt timestamps, and last error summaries.
- Make workers safe to run in multiple processes.
Concurrency Rules
Read references/concurrency.md when duplicate requests, locks, isolation
levels, or unique constraints are part of the fix.
Use the database as the source of truth for deduplication when multiple app
instances can process the same workflow.
Reference Files
references/idempotency.md: idempotency keys, save-and-replay, and request
payload binding.
references/background-workers.md: queue tables, worker loops, retry
boundaries, and outbox behavior.
references/concurrency.md: lock choices, transaction isolation, and duplicate
request tests.
1---2name: rust-idempotent-workflows3description: Use when designing, implementing, testing, or debugging Rust service workflows that must be safe under retries, duplicate requests, crashes, concurrent submissions, background workers, queues, email/payment/notification side effects, idempotency keys, transaction isolation, or save-and-replay API behavior.4license: MIT5---67# Rust Idempotent Workflows89Use this skill to make Rust workflows reliable when clients retry, workers10crash, requests race, and external side effects cannot be rolled back.1112## Core Workflow13141. Write the failure story before writing code. List what happens if the process15 crashes after each database write and after each external side effect.162. Identify the idempotency boundary: HTTP endpoint, command handler, queue job,17 webhook, or external callback.183. Choose the idempotency strategy:19 - Natural idempotency from a unique business key.20 - Client-provided idempotency key with save-and-replay.21 - Server-generated deduplication key.22 - Outbox or queue table for side effects.234. Put state transitions and idempotency records in the same transaction when24 they must agree.255. Make duplicate concurrent requests deterministic. Use unique constraints,26 locks, serializable transactions, or explicit conflict handling.276. Treat external side effects as at-least-once unless the provider guarantees28 more. Store enough state to retry or reconcile.297. Add tests for duplicate requests, retry after timeout, concurrent requests,30 crash windows when practical, and worker retry behavior.3132## Idempotency Key Rules3334Read `references/idempotency.md` before adding idempotency keys or save-and-35replay behavior.3637- Bind the key to the authenticated user or tenant.38- Store a hash of the request payload when replaying responses.39- Return the original response for exact replays.40- Reject reuse of the same key with a different payload.41- Expire records only after product and provider retry windows have passed.4243## Background Work Rules4445Read `references/background-workers.md` when adding queue tables, polling46workers, retries, or external side effects.4748- Commit durable intent before sending external effects.49- Use `pending`, `in_progress`, `succeeded`, and `failed` states deliberately.50- Keep retry counts, next-attempt timestamps, and last error summaries.51- Make workers safe to run in multiple processes.5253## Concurrency Rules5455Read `references/concurrency.md` when duplicate requests, locks, isolation56levels, or unique constraints are part of the fix.5758Use the database as the source of truth for deduplication when multiple app59instances can process the same workflow.6061## Reference Files6263- `references/idempotency.md`: idempotency keys, save-and-replay, and request64 payload binding.65- `references/background-workers.md`: queue tables, worker loops, retry66 boundaries, and outbox behavior.67- `references/concurrency.md`: lock choices, transaction isolation, and duplicate68 request tests.