# ADR : Idempotent handling of Status: proposed — template; decision and owner acceptance are not recorded. Date / source revision / owner / supersedes: ## Context and decision trigger Identify the state-changing operation, producer/consumer and duplicate sources (caller retry, broker redelivery, n8n retry, manual replay). State the harm from duplicate effects and the delivery/latency/retention requirements. A read-only or naturally idempotent operation may not need a deduplication store; justify that conclusion. ## Invariant and failure windows For a defined tenant/operation/business key and semantically equivalent request, repeated processing must not repeat the protected effect within the agreed deduplication boundary/window. Define which database writes and external side effects are inside/outside this guarantee. Do not equate an n8n execution ID with a stable business idempotency key. Analyze: concurrent first deliveries; crash after claiming before applying; crash after local commit before acknowledgment; external success followed by response loss; key expiration and operator replay. Idempotency alone does not prevent different events from racing on the same business invariant. ## Alternatives and tradeoffs | Option | Applicable conditions | Limitation / cost | |---|---|---| | Naturally idempotent state assignment or business uniqueness | Repetition is equivalent by domain contract | External effects and stale updates still need analysis | | Atomic inbox/idempotency record coupled to local transaction | Protected state and claim share a transactional boundary | Retention, contention and recovery logic; verify actual provider semantics | | Provider idempotency key plus local reconciliation | Remote provider offers the required scope/window | Verify provider version/retention and ambiguous-result lookup; not a universal exactly-once guarantee | | Best effort / accept duplicates | Product explicitly tolerates the effect | Requires actual owner agreement and visible operational consequences | A separate check-then-insert, process-local cache or workflow static state is not evidence of atomic durable deduplication across workers. ## Decision to complete Choose and justify: key source/tenant/operation scope; payload normalization/hash and mismatch behavior; atomic claim/store/unique constraint; in-progress conflict response; completion/result replay; expiry window; recovery of abandoned claims; external provider key/mapping and reconciliation owner. Record existing contract compatibility and alternatives rejected with evidence. Pending choices remain unresolved. ## Validation and acceptance - Duplicate sequential and simultaneous requests with one key yield the agreed single protected effect and defined responses. - Same key with different relevant payload is rejected or handled by the explicitly chosen contract. - Inject failure at each claim/commit/acknowledgment/external-result window; recover without silent loss or duplicate protected effects within the stated boundary. - Exercise tenant separation, expired keys, replay and provider retention mismatch. Record actual commands, target/provider versions, observed effects and evidence; these are planned tests until executed. ## Consequences, rollout and rollback Specify storage/retention/PII/cost, operational visibility, migration/backfill, compatible rollout and replay procedures. Rollback must preserve deduplication history or explicitly reconcile duplicate risk; restoring workflow JSON cannot retract an external effect.