Webhook
Why it matters
Webhooks make connections between tools feel instant and cheap. A payment provider tells your database about a new subscription the second it happens. A failed charge can trigger a follow-up email immediately, instead of being noticed days later. There is no wasteful repeated checking.
The catch is reliability. A webhook can arrive twice, arrive out of order, or be retried after a timeout. Anyone building one, including with an AI tool, needs to design for that.
How to apply it
- Check whether an event has already been processed before acting. Store each event's id and skip repeats.
- Verify the sender's signature on every message. Without this, anyone who finds the address can send fake events.
- Cope with out-of-order events, for example a "cancelled" notice arriving before "created".
- Reply quickly with a success code and do the heavy work afterwards, so the sender does not retry needlessly.
- Log every event received, so a missing update can be traced to a webhook that failed or never arrived.
What it is
A webhook reverses the usual direction of a request. Normally your software asks another service "has anything changed?". With a webhook, you give the other service a web address in advance, and it sends a message to that address the instant an event occurs: a payment succeeds, a form is submitted, a deal changes stage. The receiving code then reacts. This is sometimes called a push, in contrast to polling, where you ask again and again.
Common mistakes
- Trusting every message. Without signature checks anyone who finds the address can send a fake "payment succeeded" event.
- Assuming each event arrives once. Retries are normal, so processing the same event twice must be harmless.
- Assuming events arrive in order. Handle "cancelled" before "created" without breaking.
- Doing slow work before replying. If the response takes too long, the sender retries and the work runs twice.
- Not logging what arrived. When a customer says they paid and the account is not active, you need the event history to see what happened.
- Having no way to replay. Keep a way to re-run missed events, because the sender stops retrying eventually.