Idempotency Keys: The One API Pattern That Prevents Duplicate Payments (and Worse)
This article explains how idempotency keys solve the problem of duplicate orders or payments when users retry failed requests. An idempotency key is a client-generated UUID sent with POST/PATCH requests. The server stores the key and its result (e.g., in Redis with a TTL). If the same key arrives again, the server returns the cached response instead of re-executing the operation. A minimal Express.js implementation using Redis is shown, including middleware that checks for existing keys and stores new results. The pattern is critical for payment APIs and any system where duplicate mutations cause harm.
// why it matters
Prevents duplicate payments and data corruption from retries, a must for reliable APIs.