DEV Community

Cover image for Give your webhook docs a retry button
bzucker4
bzucker4

Posted on Edited on

Give your webhook docs a retry button

A JSON example shows what a webhook payload looks like. A retry button can show what your integration is expected to do when that same event arrives twice.

Take a fictional invoice.paid event. The receiver records the payment, but the connection drops before the sender sees the acknowledgment. The sender tries again. From the sender’s perspective, the first delivery is still unresolved. From the receiver’s perspective, the event may already be handled.

That’s a useful scenario to put beside the quickstart because the reader can see the difference between an event and a delivery attempt.

Keep the same event ID on retry

Use a stable sample payload in the docs:

{
  "id": "evt_demo_42",
  "type": "invoice.paid",
  "data": {
    "invoice_id": "inv_demo_17",
    "amount_cents": 4900,
    "currency": "USD"
  }
}
Enter fullscreen mode Exit fullscreen mode

Give the demo two buttons, Send sample and Retry same event. Keep the payload visible next to the delivery log. In this example the attempt number belongs to the log. The event ID stays evt_demo_42 in both payloads.

Attempt What the sender sees What the receiver records
1 No acknowledgment received Payment recorded for evt_demo_42
2 200 OK Event already handled. Payment record count stays at 1.

A live API can use different response codes or retry conditions. If this demo documents a real API, use its actual contract for the sender column. Show a reset control so the reader can run the same sequence again from an empty state.

Make the receiver’s state visible

A teaching demo can represent successful processing with a set of handled event IDs. This bit of JavaScript runs on its own and models the receiver’s side:

const handledEvents = new Set();

function receiveSample(event) {
  if (handledEvents.has(event.id)) {
    return { outcome: "already handled", records: handledEvents.size };
  }

  handledEvents.add(event.id);
  return { outcome: "payment recorded", records: handledEvents.size };
}

const sample = { id: "evt_demo_42", type: "invoice.paid" };
console.log(receiveSample(sample)); // payment recorded, records: 1
console.log(receiveSample(sample)); // already handled, records: 1
Enter fullscreen mode Exit fullscreen mode

The first simulated timeout happens after receiveSample returns. That order matters. If you simulate the timeout by skipping the first call, the retry becomes the first successful delivery and never exercises the duplicate case.

The set lives in browser memory. For a real receiver that records payments in a database, keep the deduplication record and the payment write in the same transaction, with a uniqueness constraint on the provider’s event ID scoped to its account or stream where appropriate. Then two simultaneous deliveries can’t both claim the same event. The demo teaches the behavior while keeping the UI small.

Let the reader copy the example safely

Use fictional IDs and a sample payload shaped like the one in your quickstart. Mark the timeline as a simulation, especially if an endpoint URL appears onscreen. Keep the payload copyable and put the result in text so a reader can follow the sequence with a keyboard and without animation. A regular table beneath the demo gives anyone reading straight through the same information.

One way to review your docs is to hand them to someone who hasn’t seen your integration. Ask them to predict what happens after they press retry. If they can point to the unchanged event ID and the record count of one, the demo has done its job.

This example is inspired by a Framer component I sell through Atlas Creative. Interactive Webhook Playground.

Top comments (0)