Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

iTechGuides is reader-supported. When you buy through links on our site, we may earn an affiliate commission. As an Amazon Associate I earn from qualifying purchases. Learn more

Idempotency is how an API can recognize that two requests are attempts to carry out the same operation, rather than two separate purchases. If a payment request times out, the client can retry it with the same idempotency key; a supporting service can then avoid repeating the charge and return the original result. This depends on the client reusing the key and the service implementing deduplication correctly—it is not a promise that every request is delivered only once.

Why one purchase can produce more than one request

Suppose you click Pay once. The payment service processes the request, but its response is delayed or lost. Your browser cannot tell whether the payment went through, so you click again or the software retries automatically. The two network attempts may represent one purchase intent.

Without a way to recognize that shared intent, the service could process both attempts and create two charges. With idempotency, the client attaches the same key to retries of the original operation. The service can associate the repeated request with the first operation and preserve or return its result. Stripe describes this as a way to retry requests without accidentally performing the same operation twice: Stripe’s idempotent requests documentation.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

What an idempotency key does—and does not do

An idempotency key is an identifier for one logical operation, such as one attempt to create a particular payment. It lets a service distinguish a retry from a new request. The key does not make the network deliver a request exactly once, and it cannot by itself ensure that every later step in a distributed workflow happens only once.

#1 Best Overall
Square Terminal - Credit Card Machine to Accept All Payments | Mobile POS
  • With Square Terminal, you can ring up sales, accept payments, and print receipts, all with one device. Use it at the counter or ring up customers anywhere in your store.
  • Accept all major credit and debit cards and pay one low rate with no hidden fees and no long-term contracts.
  • Process chip cards in just two seconds.
  • Get your money as soon as the next business day.
  • Use it cordlessly with the built-in battery, designed to last all day.

A service’s behavior depends on its own rules: which requests share a key scope, whether parameters must match, whether it replays the first response, how long it retains keys, and how it handles simultaneous requests. Downstream services and message consumers also need suitable duplicate handling. AWS recommends passing the token to downstream services and tracking duplicate message tokens where appropriate: AWS Well-Architected guidance on mutating operations.

How to use keys for safe retries

  1. Create one key for one intended operation. For example, generate a unique key when the customer submits a particular payment.
  2. Reuse that exact key for retries of that operation. If a timeout leaves the outcome uncertain, retry with the same key rather than creating a new one.
  3. Keep the operation’s parameters consistent. Providers may reject a reused key if the new request changes the original parameters.
  4. Use a new key for a genuinely new operation. A second purchase is not a retry of the first, even if the amount is identical.
  5. Check the provider’s rules and propagate the identifier when needed. If the operation triggers downstream work, those services or consumers need their own way to recognize duplicate processing.

Provider rules differ

Idempotency is a design pattern, not a universal contract. These examples show why an implementation must be checked against its provider’s documentation.

Rank #2
Sale
Square Reader for contactless and chip (2nd Generation)
  • Use the, easy-to-use, and customizable POS to get started.
  • Accept contactless payments, chip cards, Apple Pay, and Google Pay from anywhere, with improved connectivity, extended battery life, and enhanced security. Pay one low rate for every tap or dip.
  • No long-term commitments or contracts, no monthly fees- and with offline payments, keep taking payments for up to 24 hours.
  • Safely and securely accepts payments anywhere. Plus, get data security, 24/7 fraud prevention, and payment-dispute management at no extra cost.
  • Use the, easy-to-use, and customizable POS to get started.
Behavior Stripe Amazon Pay
Key format and limit UUID v4 or another random string with sufficient entropy; up to 255 characters, according to Stripe. Up to 32 characters from a specified character set, according to Amazon Pay.
Changed parameters with the same key Must match the original request; otherwise Stripe returns an error. Returns a DuplicateIdempotencyKey error.
Retention Keys may be pruned once they are at least 24 hours old; reusing a pruned key can start a new request. Keys are stored indefinitely and scoped to a merchant account.
Result handling After endpoint execution begins, Stripe saves the status and response body for the first request, including a 500 response. A repeat with the same key returns the saved result.
Concurrent requests A result is not saved when validation fails or a concurrent request conflicts before endpoint execution begins. Not stated in the cited Amazon Pay documentation.

These are provider-specific rules, not requirements that every API must follow. Stripe’s 24-hour pruning behavior also means a key should not be treated as a permanent record of a purchase. Amazon Pay’s indefinite retention and merchant-account scope are different choices, not a general standard.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Idempotency beyond payments

The same problem appears whenever a retry can repeat a mutating action: creating a cloud resource, placing a job on a queue, or processing a message. AWS documents client tokens for EC2 and ECS API requests, and its Well-Architected guidance emphasizes duplicate handling for both mutating requests and messages: EC2 idempotency and ECS idempotency.

Rank #3
Square Handheld - Portable POS - Credit Card Machine to Accept Payments for Restaurants, Retail, Beauty, and Professional Services
  • With Square Handheld, you can accept payments, take tableside orders, or scan barcodes anywhere. With a slim design and comfortable grip, the POS is easy to carry in your palm or pocket. Square Handheld is designed to withstand water splashes and dust. Add an optional protective case for accidental drops. A long-lasting battery and offline payments let you keep selling.
  • Slim, pocketable, and lightweight so you can accept payments wherever your customers are.
  • Take tableside orders, bust lines, or use the built-in barcode scanner, all with one sleek device.
  • A battery that can power through your shift and offline payments let you keep selling, even if your internet is down.
  • Accept all major credit and debit cards and pay one simple rate with no hidden fees and no long-term contracts required.

For a workflow that crosses services, one protected request does not automatically protect the whole chain. Each service that can create a side effect must handle retries appropriately; forwarding an identifier helps only if the receiving service also recognizes and uses it.

Quick Recap

Bestseller No. 1
Square Terminal - Credit Card Machine to Accept All Payments | Mobile POS
Square Terminal - Credit Card Machine to Accept All Payments | Mobile POS
Process chip cards in just two seconds.; Get your money as soon as the next business day.; Use it cordlessly with the built-in battery, designed to last all day.
$298.99
SaleBestseller No. 2
Square Reader for contactless and chip (2nd Generation)
Square Reader for contactless and chip (2nd Generation)
Use the, easy-to-use, and customizable POS to get started.; Use the, easy-to-use, and customizable POS to get started.
$47.20
Bestseller No. 3
Square Handheld - Portable POS - Credit Card Machine to Accept Payments for Restaurants, Retail, Beauty, and Professional Services
Square Handheld - Portable POS - Credit Card Machine to Accept Payments for Restaurants, Retail, Beauty, and Professional Services
Slim, pocketable, and lightweight so you can accept payments wherever your customers are.
$399.00
Best Value
Sale
Square Register (2nd Generation) - Powered by POS
  • A complete countertop point of sale — Combine dual responsive touchscreens, built-in POS software, and durable hardware for a fast, reliable checkout experience.
  • Serve customers faster — Run smoothly through busy shifts, complex menus, and big orders with high-speed processing, memory, and responsive touchscreen displays.
  • Accept every way they pay — Take all major cards at one simple rate, with no hidden fees or long-term contracts. Receive funds as soon as the next business day.
  • Handle real-world demands — Resist everyday spills, dust, and wear with a durable, IP54-rated design.
  • Stay reliable through every rush — Maintain strong connectivity and consistent performance through your busiest hours.
Rank #4
Clover Compact Payment Terminal - Requires New Merchant Processing Account Through Powering POS.
  • The Clover Compact and Clover Mini /Station sync with each other through the Clover Dashboard and cloud-based network. This allows you to manage transactions, track sales, and access business data across both devices seamlessly. Plug in, not battery/mobile. Requires New Processing account through Powering POS. (US, PR, USVI). CANNOT be used with a different Processor. Rate match guarantee. Contact us for questions

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.