Tutorial6 min read

Guide: Reliably Forward Stripe Webhooks to Your Backend

Ensure 100% delivery for your most critical business events.

Stripe webhooks are critical. They tell you when a payment succeeds, a subscription is canceled, or a dispute is opened. If your backend misses one of these events, your database gets out of sync with reality, and your customers get frustrated.

The problem is that Stripe has a relatively short timeout for webhooks. If your server is slow to respond, or if it's temporarily down for a deployment, Stripe will eventually stop retrying.

The Reliable Pattern: Stripe → Your Proxy → FetchAPI → Your Backend

Instead of processing Stripe webhooks directly, use a lightweight proxy (like a simple Edge Function or a dedicated endpoint) that immediately forwards the event to FetchAPI.

This pattern offers several advantages:

  • Instant Acknowledgment: Your proxy can respond to Stripe in milliseconds, preventing timeouts.
  • Guaranteed Delivery: FetchAPI will handle retrying the delivery to your actual processing server until it succeeds.
  • Decoupling: Your payment processing logic can be as slow or complex as it needs to be without worrying about Stripe's timeouts.

Step 1: Create a Lightweight Receiver

Create a simple endpoint that receives the Stripe webhook. Its only job is to verify the signature and relay the payload to FetchAPI.

// Example in a Next.js Route Handler
export async function POST(req: Request) {
  const payload = await req.text();
  const signature = req.headers.get('stripe-signature');

  // 1. Verify Stripe signature (omitted for brevity)

  // 2. Relay to FetchAPI
  await fetch('https://api.fetchapi.dev/v1/fetch', {
    method: 'POST',
    headers: {
      'Authorization': `Bearer ${process.env.FETCHAPI_KEY}`,
      'X-Fetch-Url': 'https://api.yourserver.com/webhooks/stripe-processor',
      'Content-Type': 'application/json'
    },
    body: payload
  });

  // 3. Respond to Stripe immediately
  return new Response('OK', { status: 200 });
}

Step 2: Process the Webhook Durably

Now, your stripe-processor endpoint can take its time. It can run complex database queries, send emails, or call other third-party APIs. If it fails, FetchAPI will retry the request.

Why This is Better Than Direct Processing

When you process webhooks directly, you're at the mercy of the network and your server's uptime. If your server restarts during a deployment while Stripe is sending a customer.subscription.deleted event, you might miss it.

With FetchAPI in the middle, you have a durable record of every event. You can see exactly what was sent, when it was delivered, and any errors that occurred during processing.

Conclusion

Don't leave your revenue to chance. By using FetchAPI to relay Stripe webhooks, you ensure that every critical event is processed reliably, no matter what happens to your backend.

Secure Your Revenue

Stop worrying about missed Stripe webhooks. Use FetchAPI for guaranteed delivery and peace of mind.

Get Started Free