Duplicate webhook delivery
Processors retry events whenever a response is slow. Without database-level idempotency keys, retries grant duplicate credits or create duplicate journal lines.
Reference Blueprint · IllustrativeAPIs & PaymentsTypical starter sprint: 4 weeks
Idempotent Stripe + Apple subscription processing backed by a double-entry Postgres ledger and automated nightly reconciliation.
Request a scoped plan for your stack → Book a 20-minute call
System design
HMAC signature check + raw payload stored in append-only event log.
Unique constraint on provider_event_id prevents double charges or duplicate grants.
Balanced debit/credit journal rows updated atomically with entitlement state.
Compares gateway settlement totals against ledger; flags exceptions to finance same-day.
| Event | Idempotency Key | Ledger Status | Reconciliation |
|---|---|---|---|
invoice.paid | evt_stripe_91a8c | Posted | Matched settlement |
invoice.paid (retry) | evt_stripe_91a8c | Skipped (duplicate) | No double entry |
charge.dispute.created | evt_stripe_72f01 | Hold posted | Alerted finance queue |
Why teams get stuck
Processors retry events whenever a response is slow. Without database-level idempotency keys, retries grant duplicate credits or create duplicate journal lines.
An invoice.paid event arriving before customer.subscription.created breaks naive CRUD updates and leaves paying users locked out.
Web subscriptions on Stripe and iOS subscriptions on Apple IAP follow different renewal, grace-period and refund lifecycles.
Teams discover missed refunds, partial disputes or failed captures weeks later in a spreadsheet instead of on the day they occur.
How we engineer it
Verify provider signatures at the edge, persist the raw payload immediately, and return 200 fast so processor retries stay clean.
Process events asynchronously with transactional locks and explicit state transitions (trialing, active, past_due, grace, revoked).
Never overwrite balances. Record immutable debit/credit entries for charges, fees, taxes, refunds and chargebacks.
Scheduled job compares processor settlement exports against internal ledger rows and alerts Slack/email on any penny mismatch.
What lands in your repo
Verification gates
Measurable engineering gates agreed before kickoff—verified in your staging environment before sign-off.
Execution cadence
Audit current billing code, map every money touchpoint, and lock schema + state-machine design.
Build signed ingestion, idempotency gate and transactional entitlement service with replay tests.
Implement double-entry ledger tables, refund/dispute handling and nightly reconciliation job.
Shadow-run against production events, wire alerts, complete runbook and cut over safely.
← Back to all blueprints & Ritgro case study · Run the Launch Readiness Checklist →
Start a project
Share a few lines about your stack and timeline. A senior engineer responds within one business day—or grab a 20-minute slot directly.
Direct: (469) 453-7654 · hello@appandapi.com
RuyoTech LLC · Dallas, Texas (US Central time)
Thank you. A senior engineer will review your note and reply within one business day. Want to lock a time right now? Pick a 20-minute slot.