A practical guide to building reliable webhook handlers for post-payment flows using durable background jobs. The naive approach of processing everything inline in a single webhook handler leads to duplicate emails, partial state, and unrecoverable failures when any step fails mid-execution. The solution is to keep the webhook endpoint minimal (validate signature, enqueue event, return 200) and move all processing into a durable function where each step is individually checkpointed. Using TypeScript with Node.js and the durable execution platform, each operation (database writes, emails, GitHub API calls, analytics) becomes its own retryable step. If step 5 fails, steps 1-4 don't re-run. The pattern also covers refund handling, abandoned checkout recovery using step.sleep(), and local testing with the CLI and dev dashboard.

26m read timeFrom freecodecamp.org
Post cover image
Table of contents
PrerequisitesTable of ContentsWhy Stripe Webhooks Fail SilentlyThe Naïve Approach (and Why It Breaks)The Pattern: Webhook to Event to Durable FunctionHow to Set Up the Webhook EndpointHow to Build a Durable Purchase FlowHow to Handle Refunds with the Same PatternHow to Recover Abandoned CheckoutsHow to Test Webhook Handlers LocallyConclusion

Sort: