Idempotency Keys in Marketplace & Payment Webhooks: Architecture Guide


Idempotency keys are deterministic client-generated identifiers (such as a UUIDv4 or composite order_id:payout_step string) attached to payment API requests and webhook handlers so that retrying the same operation produces the exact same result without executing a duplicate charge, transfer, or ledger entry.
Two-sided marketplaces orchestrate multi-step money movement across Stripe Connect, Sharetribe transaction transitions, and internal PostgreSQL ledgers. Network timeouts and Stripe's 72-hour automatic webhook retry schedule guarantee that production handlers receive the same event more than once. Without idempotency guards, a single timeout during a payment_intent.succeeded webhook can trigger two seller transfers, double-decrement inventory, or send duplicate payout notifications.
| Layer | Key Pattern | Failure Prevented |
|---|---|---|
| Outbound Stripe API Calls | Idempotency-Key: order_{id}_transfer_v1 |
Double seller payouts after 504 gateway timeouts (Stripe caches keys for 24 hours) |
| Inbound Webhook Consumer | PostgreSQL UNIQUE(stripe_event_id) inside DB transaction |
Duplicate ledger credits during concurrent webhook deliveries |
| Checkout Submit Button | Cart-version hash bound to payment intent creation | Double buyer charges on mobile double-tap or flaky Wi-Fi |
Stripe-Signature HMAC header before writing the event ID to your deduplication table.INSERT INTO processed_events (event_id) VALUES ($1) ON CONFLICT DO NOTHING inside the same SQL transaction that updates the order ledger.200 OK so Stripe stops retrying without masking genuine 500 errors.Related architecture guides: Implementing Stripe Connect for Marketplace Payouts, Managing Refunds & Chargebacks with Stripe Connect, and Horizon Labs Sharetribe Engineering.
Horizon Labs audits webhook reconciliation, split payouts, and dispute flows with founder responses in under 1 hour.
Request Technical ScopingTell us what you're building. After an intro call with our founders, you'll hear back within 72 business hours: a written scope with an hour range and a hard ceiling, or the questions we need answered first.