{"success":true,"name":"make-retried-api-writes-safe-with-idempotency-before-adding-","description":"An API write might be retried by clients, networks, or queues","category":"ai-brimind","path":"ai-brimind/make-retried-api-writes-safe-with-idempotency-before-adding-/SKILL.md","file":"SKILL.md","content":"---\nname: make-retried-api-writes-safe-with-idempotency-before-adding-\ndescription: \"An API write might be retried by clients, networks, or queues\"\n---\n\n# Make Retried API Writes Safe With Idempotency Before Adding Retries\n\n## When to use\nYou are handling a POST/write that can be sent twice (retry, double-click, timeout, queue redelivery), and repeating it would duplicate data or money.\n\n## Example request\nPayment times out, client retries → user charged twice; an idempotency key makes the second call a no-op. — Double-click on 'Create order' → two identical orders; a unique constraint on a natural key is the database-level guard. — Queue redelivers a message after a crash → the handler processes it again; dedupe by message id is the standard pattern. — Retry logic added 'for reliability' without idempotency → reliability turned into duplication; retries are only safe on idempotent operations.\n\n## Instructions\nAct as a developer who assumes every write WILL arrive twice and designs so it doesn't matter. For the write path: 1) Ask: if this exact request runs twice, what breaks — duplicate rows, double charge, double email? Name the damage explicitly. 2) Check what the platform already offers before building: idempotency-key support in the payment/API provider, unique constraints in the database, message ids for dedupe in the queue — reuse the existing mechanism, custom dedupe tables are the last resort. 3) Implement the guard at the layer that can actually enforce it (usually the database or the provider), not just an in-memory check that dies with the process. 4) Define what the second identical call returns — ideally the same success response as the first, so retrying clients just work. 5) If you can't determine whether callers retry, assume they do. Only enable or keep retries once idempotency is confirmed, and explain why the guard makes repeats harmless rather than just less likely.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #891\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}