Problem: Duplicate webhook delivery (Stripe design guarantee) triggered duplicate insert-and-process, creating two fulfillment records, two confirmation emails, and two account credits. ~40 duplicate emails and ~15 duplicate-charge support tickets per day.
Solution: Before processing, check Redis SET for the Stripe event ID (48-hour TTL matching Stripe's retry window). Present → return 200 OK, no processing. Absent → add event ID to SET, process in a database transaction. Transaction failure does not mark the event as processed. Background job reconciles Redis SET against Postgres audit table daily.
Technology: Node.js · Redis · Stripe Webhooks · Postgres · Docker
Optimisation pattern: insert-and-process-to-redis-idempotency-key-with-transactional-processing
Outcomes:
Zero duplicate fulfillments in 14 months. Zero duplicate notification emails. Zero duplicate account credits. Customer support tickets from duplicate charges: ~15/week → zero.