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
WITHOUT WEBHOOKS β your server polls someone else's
Your API ββ"paid yet?"βββΊ Stripe no
Your API ββ"paid yet?"βββΊ Stripe no
Your API ββ"paid yet?"βββΊ Stripe YES (30s late)
WITH WEBHOOKS β they call you, once, immediately
Stripe ββPOST /webhooks/stripeβββΊ Your API
{ type: "payment_intent.succeeded", ... }
βββββββ 200 OK (fast, before you do the work) ββTHE FULL CHAIN β webhook ends at your server, not at the user
ββββββββββ webhook ββββββββββββ SSE/WS/push βββββββββββ
β Stripe β ββββββββββΊ β Your API β βββββββββββββββΊ β Browser β
ββββββββββ POST ββββββββββββ βββββββββββ
β
βββΊ queue β email, ledger, fulfilment
A webhook can never reach a browser directly: browsers have no URL.DELIVERY REALITY β assume every event arrives twice, or late
attempt 1 β 500 β
attempt 2 β timeout ββ provider retries with backoff
attempt 3 β 200 β
βββ attempt 1 may already have run
β deduplicate by event idHow 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.