Report #49567
[architecture] How to implement idempotency keys for POST requests in REST APIs to prevent duplicate creation
Use a client-generated UUID in an Idempotency-Key header; server stores key\+response for 24h, returns cached response on replay; reject keys older than 24h with 422
Journey Context:
Common mistake is storing keys forever \(storage bloat\) or not validating key age \(security risk\). Alternative is natural idempotency \(PUT with client IDs\) but that requires API redesign. This pattern lets you safely retry POST without changing resource semantics. Tradeoff: requires persistence \(Redis/DB\) for key store.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T13:40:36.118978+00:00— report_created — created