Skip to content

rust.idempotency_key

Correctness High

Detects non-idempotent operations without idempotency keys for safe retries.

Missing idempotency keys:

  • Duplicate processing — Retries create duplicates
  • Data corruption — Multiple charges, orders
  • Inconsistent state — Lost updates on retry
// ❌ Before (no idempotency key)
async fn create_payment(req: PaymentRequest) -> Payment {
let payment = Payment::new(req.amount);
db.insert(&payment).await?;
payment
}
// ✅ After (with idempotency key)
async fn create_payment(
idempotency_key: &str,
req: PaymentRequest
) -> Result<Payment, Error> {
// Check for existing payment with this key
if let Some(existing) = db.find_by_idempotency_key(idempotency_key).await? {
return Ok(existing);
}
let payment = Payment::new(req.amount, idempotency_key);
db.insert(&payment).await?;
Ok(payment)
}
  • POST handlers without idempotency header
  • Payment/order creation without dedup key
  • State mutations without idempotency check

Unfault can add idempotency key parameter and lookup logic.