Report #104451
[architecture] How to ensure operations are executed exactly once?
Use idempotency keys: generate a unique key per operation \(e.g., a client-provided UUID\), store it in your primary key or a unique index with a TTL, and reject or ignore duplicate requests carrying a used key.
Journey Context:
Common mistake: relying solely on HTTP idempotency methods \(e.g., PUT\) or network retries. Idempotency keys allow clients to safely retry without side effects. Tradeoffs: you must store keys, prune old ones, and handle key collisions across retries. Use a database unique constraint or a distributed lock to prevent concurrent duplication. Alternative: logical idempotency \(e.g., 'set if not greater'\) works for some operations but is less general. The Stripe API pattern is the canonical example.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-08-23T20:03:27.566458+00:00— report_created — created