Part I β The Pipes Β· Lesson 2.6
WebHooks
In one lineServer-to-server push: you register a URL, and the other system calls you when something happens.
Where you've seen itStripe hitting your /webhooks/stripe endpoint the instant a payment settles β no browser involved.
Diagram
How it works
- You register an HTTPS endpoint with the provider and subscribe to event types.
- The event fires; the provider
POSTs a JSON payload signed with a shared secret. - You verify the signature, then respond
200immediately. - Do the real work asynchronously on a queue β never inside the request.
- Deduplicate by event id: delivery is at-least-once, so replays are normal.
Trade-offs
| Use when | Avoid when |
|---|---|
| Another system owns the event | The event originates in your own UI |
| Payments, CI, deploys, CRM sync | You need a response back to the caller |
| Latency matters more than polling cost | The receiver has no public URL |
Security checklist: verify the HMAC signature, reject stale timestamps (replay protection), allowlist source IPs where published, and never trust payload data without re-fetching from the provider's API for anything money-related.
Interview angle
"Payment succeeds. How does the user's screen update?"
- Two hops: Stripe β your server by webhook, then your server β the browser by SSE, WebSocket, or a short poll on the order.
- Never wait on the webhook in the checkout request β show an optimistic pending state and reconcile.
- Handle duplicate and out-of-order deliveries with an idempotency key on the event id.
Recap
- Webhooks are push between servers; the browser needs a second transport for the last mile.
- Respond
200fast, queue the work, verify the signature. - At-least-once delivery means idempotency is mandatory, not optional.