hebel. today · 18 November 202671 / 80

Technology · Software Architecture Patterns

Payment endpoints enforce idempotency through order-bound keys

Stripe, Adyen, and Square recommend random idempotency keys per request to protect against network retries, but this method fails when a user reloads a page or opens a second tab. Payment teams now link…

Stripe, Adyen, and Square recommend random idempotency keys per request to protect against network retries, but this method fails when a user reloads a page or opens a second tab (The T-Shaped Dev). Payment teams now link the idempotency key to a server-created order ID instead of the individual click, ensuring that every retry for a single purchase uses the same key. This approach forces the payment provider to recognize subsequent attempts as replays of the original transaction, preventing duplicate charges (The T-Shaped Dev).

Engineers implement a partial unique index on the payments table using the SQL command CREATE UNIQUE INDEX one_live_payment_per_order ON payments (order_id) WHERE status <> 'declined'. This database constraint allows only one successful payment attempt per order, effectively acting as the final arbiter of state. When a server crash occurs before saving a result, a 30-second lease on the payment row allows a subsequent request to take over the attempt and re-send the original card details to the provider.

This design creates a reliable seam between internal state and external payment providers, mirroring how Netflix and Uber use API gateways to isolate internal services from unstable external traffic (Hands On System Design, Hands On System Design). By queuing receipts and events in the same database statement that marks a payment as successful, systems guarantee that customers receive exactly one confirmation for their purchase.

Try today · 15 min

Implement a partial unique index on your payments table to prevent duplicate charges per order.

Run the SQL command provided in the source to lock status-based payment attempts.

You need

  • Access to your database schema
  • The order_id column in your payments table

Steps

  1. Identify the payments table in your database schema.
  2. Verify that your payments table includes an order_id column.
  3. Execute the SQL command: CREATE UNIQUE INDEX one_live_payment_per_order ON payments (order_id) WHERE status <> 'declined';
  4. Test the constraint by attempting to insert two payments with the same order_id.

One email instead of your newsletter pile.

Forward the newsletters you already get (a Gmail filter does it) and tell Hebel your goals. Every morning it reads them with 20,000 others and sends one short email, with one small thing to do today. Fewer emails, not more. Free during beta.

Start my paper →
LinkedIn X

Sources

  1. The T-Shaped Dev on hebel. →This article details why order-bound idempotency keys and partial unique indexes are superior to request-bound keys for preventing duplicate payments.

  2. Hands On System Design on hebel. →This entry explains how API gateways function as seams to protect internal services from external client instability and garbage input.

More in Technology

Global innovation shifts beyond traditional urban hubs

Autonomous exploit pipelines compress the patch-to-breach window

Automating workflows with multi-agent teams versus task-based prompts

Auditing your digital footprint to reclaim dormant data

Interfaces shift from visual navigation to machine-readable tool calls

Gemini Robotics 2.5 reaches 96% success in automotive kitting

Software Architecture Patterns yesterday

Monoliths remain the default for early-stage product teams

Sign in to Hebel first

Likes, your collection and done Hebel need an account. We email you a six digit code; no password.