Glossary · Marketplaces · 5-min read

Idempotency Keys in Marketplace & Payment Webhooks: Architecture Guide

Marketplace webhook idempotency architecture showing payment request, unique lock shield, and deduplicated ledger

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.

Why Marketplace & Stripe Connect Systems Require Idempotency

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

Implementation Rules for Production Marketplaces

  1. Verify Webhook Signatures First: Validate the Stripe-Signature HMAC header before writing the event ID to your deduplication table.
  2. Insert Event ID Atomically: Run INSERT INTO processed_events (event_id) VALUES ($1) ON CONFLICT DO NOTHING inside the same SQL transaction that updates the order ledger.
  3. Return HTTP 200 on Duplicates: Acknowledge already-processed events with 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.

Need a Stripe Connect or Sharetribe Payment Audit?

Horizon Labs audits webhook reconciliation, split payouts, and dispute flows with founder responses in under 1 hour.

Request Technical Scoping
No items found.

See what your project would cost.

Tell 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.

Get an estimate
Book a call