Payment APIs are where distributed systems bugs become financial bugs. Idempotency design has to be explicit and auditable.
Record Shape
type IdempotencyRow = {
key: string;
requestHash: string;
status: "inflight" | "committed" | "rejected";
responseJson: string;
};Failure Handling
- Same key + same hash => replay prior response.
- Same key + different hash => hard reject.
- Inflight collision => client retry with backoff.
Idempotency is a correctness contract, not an optimization layer.