Report #15541
[architecture] How to implement idempotency keys without unbounded storage growth or cross-tenant collisions
Store idempotency keys with a TTL \(e.g., Redis EXPIRE or DynamoDB TTL\) matching your maximum replay window \(usually 24h\), and shard/namespace keys by account \+ endpoint to prevent cross-tenant pollution; never rely on unique database constraints alone without expiration.
Journey Context:
Naive implementations store idempotency keys in SQL tables with unique indexes indefinitely, creating storage bloat and performance degradation. Keys must expire because: \(1\) business context changes \(prices, inventory\), \(2\) regulatory data retention limits \(GDPR\), \(3\) attack surface reduction \(preventing replay of ancient requests\). Redis is ideal due to built-in TTL and atomic check-and-set \(SET key value NX EX seconds\), but requires persistence configuration \(AOF\) to prevent key loss on restart. SQL databases can implement TTL via partitioned tables with scheduled cleanup, but this adds operational complexity. Cross-tenant key collisions \(user A submits key '123', user B submits key '123'\) require prefixing keys with tenant ID or endpoint path \(e.g., 'acct\_123:create\_charge:uuid'\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T00:22:20.734059+00:00— report_created — created