Idempotency Key — Safe Retries

Idempotency Key — Safe Retries A sequence diagram generated by Archify. POST /payments (Idempotency-Key: K) insert K as IN_PROGRESS (unique) charge (PSP key K) approved save K → 201 + body response lost (timeout) POST /payments (same key K) lookup K COMPLETED: stored 201 201 (replayed, no new charge) First attempt Retry Client · mobile app · Sequence participant Client mobile app Payments API · idempotent POST · Sequence participant Payments API idempotent POST Idempotency store · key → response · Sequence participant Idempotency store key → response PSP · card network · Sequence participant PSP card network Legend request return security async trace default message

Contract

  • • Client generates one key per logical operation
  • • Same key + same body → same result

Concurrency

  • • Unique insert stops two in-flight duplicates
  • • IN_PROGRESS requests get 409 or wait

Retention

  • • Keys expire after e.g. 24 h
  • • Different body with same key → 422