noted.do
The Tech Guy

Webhooks Are Just APIs Calling You Back

Most of the time, your code is the one asking. You call an API and say "has this payment gone through yet?" and it answers. If you need to know the moment something changes, you have to keep asking every few seconds, which is wasteful for you and annoying for them.

A webhook flips that around. You give the other service a URL on your side, and when something happens it sends an HTTP request to that URL with the details. A payment succeeds, someone pushes to a repo, a form gets submitted, and your app hears about it right away. "Don't call us, we'll call you," basically.

Under the hood it's nothing exotic. Usually it's a POST request with a JSON body describing the event, something like an event type, an ID and the relevant data. Your endpoint reads it, does whatever it needs to, and responds with a 2xx status so the sender knows it arrived.

The concept is simple. Doing it well takes a few habits.

Verify it's real. Your webhook URL is just a public URL, and anyone can send a POST to it. Most services sign each request, typically with an HMAC of the body using a shared secret, and put the signature in a header. Check that signature on every request before you trust anything in it, using a constant-time comparison (like hash_equals in PHP). Use the raw request body for the check, not a re-encoded version, or the signatures won't match.

Respond fast. Senders usually give you a short window before they treat the request as failed. Don't send emails or resize images inside the handler. Save the event, return 200, and do the slow work in a background job.

Expect duplicates. If your response was slow or got lost, the sender will retry, so you'll sometimes get the same event twice. Store event IDs and skip ones you've already processed. Otherwise you'll end up sending two receipts or granting two upgrades.

Don't assume order. Events can arrive out of sequence. If it matters, check timestamps or fetch the current state from the API instead of trusting the order things showed up.

Most services also have a dashboard showing recent deliveries and whether they failed, plus a way to resend them. That's the first place to look when something isn't working, and it'll save you a lot of guessing.

Comments

Be kind. See the rules.