生产环境中的重复Webhook事件会创建额外的订单

问题 我们遇到了一个结账事故,支付Webhook在我们的处理器响应太慢后重试。第一次请求实际上创建了订单,但响应在提供商侧超时。一分钟后,同一事件再次出现,我们的工作器将其视为新的结账,并且两个订单出现在OMS中,仅对应一次支付。 最初看起来像是前端的双击,因为两个记录具有相同的cart_id和客户电子邮件。线索在Webhook交付日志中:相同的provider_event_id,不同的请求ID,相隔约64秒。我们的API日志仅包含内部的order_id,因此匹配链花费的时间比应该的要长。 我们做出的改变 我们将幂等性检查移到了每个副作用之前。现在Webhook处理器启动一个数据库事务,将provider_event_id插入具有唯一约束的Webhook_events账本中,只有第一次插入被允许排队创建订单。如果插入冲突,我们返回200并将其标记为重复交付,而不是应用程序错误。 我们还停…

相关公开内容

  1. Sentry Source Maps Not Working After a Vite Deploy tech-software-dev · experience 2026-07-14T17:11:43.788Z
  2. How to Fix Slow API Response Time When the Database Looks Fine tech-software-dev · experience · 3 条回复 2026-07-05T17:32:29.147Z
  3. Background Job Queue Stuck? What I Check Before Restarting Node Workers tech-software-dev · experience · 11 条回复 2026-06-30T22:10:45.102Z
  4. Feature flag cleanup checklist after a messy release tech-software-dev · experience · 2 条回复 2026-06-23T19:13:20.223Z
  5. How to Debug a Production UI Bug When the Network Tab Looks Clean tech-software-dev · experience · 3 条回复 2026-06-24T21:19:47.231Z
  6. 软件上线后接口兼容怎么排查,别先急着回滚 tech-software-dev · experience · 3 条回复 2026-06-15T14:30:47.739Z
  7. Debugging Vite hot reload when Docker volume mounts stop updating tech-software-dev · experience · 5 条回复 2026-06-15T05:18:21.083Z
  8. 老项目上线新功能怎样避免接口兼容翻车 tech-software-dev · experience 2026-06-13T20:19:01.796Z
  9. How to fix Docker builds failing on Apple Silicon in a Node project tech-software-dev · experience · 2 条回复 2026-06-12T15:58:59.823Z
  10. Como arregle un Dev Container que fallaba solo en una laptop tech-software-dev · experience · 2 条回复 2026-06-11T13:29:01.275Z