Webhooks
Webhooks that survive a bad night
For developers writing a webhook receiver, this video points BillDog webhooks at a path that always answers 503. Failed deliveries are retried for about two and a half hours, then held in the dead-letter log for replay. It also shows how to verify the signature, deduplicate by event ID, and rotate the signing secret without breaking a receiver that hasn’t switched yet.
Transcript
Tonight we pointed our webhook endpoint at a path on our receiver that always answers 503. A purchase landed while it was failing, and every try failed. The event still arrived, seventeen minutes later, once we pointed it back.
That’s the whole job of a webhook system, and it’s the part that almost never gets demonstrated.
Anyone can send an HTTP request. The hard parts are three questions you ask at four in the morning. Did this really come from them? Have I already handled this one? And if I was down, is it coming back?
Here’s the setup, in Webhooks. A sandbox endpoint on our test project, pointed at a test receiver we control, listening for new subscriptions. The signing secret is shown once. It’s blurred here, and it goes into a file only the receiver can read.
Then a real event: a Test Store purchase, which sends the same events a sandbox purchase does.
First question: is it authentic? Every delivery is signed with HMAC-SHA256, and the signature covers the timestamp and the body, not the body alone. So the receiver recomputes it over timestamp, dot, body, compares, and refuses anything that isn’t fresh. Here, five minutes.
Run it against what the receiver got: signature ok.
Now check that same delivery as if someone replayed it now, long after it arrived. The signature still matches, but the timestamp is old, so it’s refused. A signature over the body alone would stay valid forever. Binding the time in is what lets you say no.
Every delivery has a state. Delivered. And failed: a second endpoint we set to answer 400. A 4xx means your server said no, and sending it again won’t change that, so it isn’t retried.
Now the bad night. We point the endpoint at a path that always answers 503, and make another purchase. Three quick tries, a few seconds apart. All fail. So it’s queued for retry, not dropped.
A few minutes later, a fourth try. Still failing, so it waits longer. The retries come at 5, 10, 20, 40 and 80 minutes, about two and a half hours in all.
We point it back. About ten minutes later, the fifth try lands. Delivered.
Second question: have I already handled this one? Every try carries the same event ID. Keep the IDs you’ve processed and skip a repeat, because the same event can arrive more than once.
Rotating the secret is where an integration can drop events. Here the old secret keeps working for twenty-four hours. The webhook-signature header carries both signatures, so a receiver that checks it still verifies before it switches. The X-BillDog-Signature header carries only the new one.
This purchase came after the rotation. Our receiver still has the old secret. Signature ok.
One last thing, which is a refusal rather than a feature. It won’t register a private address. A webhook URL is input that anyone with access can set, and an integration that can be pointed at your own internal network is a bad day.
Signed with the time. One ID per event. Retried for about two and a half hours, then held in the dead-letter log for replay, and ten failures in a row turn the endpoint off. Rotated without a gap. None of it shows when things go well, and all of it is why tonight was fine.