Design a Webhook Delivery System
Understanding the Problem
🪝 What is a webhook delivery system? A webhook is an HTTP request a platform sends to a URL its customer controls, to say "something happened": a payment succeeded, a pull request was opened, a file finished processing. The customer registers the URL and picks the events they care about; the platform POSTs a JSON payload to it each time one occurs. A webhook delivery system is the part of the platform that looks up who wants each event and gets it to them reliably, even when their server is slow, down or misconfigured.
You may be asked this as a callback system ("when a long-running job finishes, call the URL the client gave us"). That's the same problem with one subscriber per request instead of a registry: the callback URL comes with the job, and everything else (retries, signing, isolation) is identical. You may also be asked about a sync hub: a service that pushes changes to connected apps and has to let an app that was offline for a day catch up on everything it missed. That's the catch-up half of this design, an events API with cursors, which we cover as a requirement and a deep dive.
Functional Requirements
Clarify who's who. Our platform produces events; our customers (developers building on the platform) receive them at endpoints they run.
Core Requirements
- Customers should be able to register an endpoint URL and subscribe it to event types.
- When an event occurs, the system should look up every subscribed endpoint and deliver the event to each of them.
- Failed deliveries should be retried, and customers should be able to see delivery attempts and replay events.
- A customer who missed events (endpoint down, bug on their side) should be able to fetch everything since a point in time and catch up.
Below the line (out of scope)
- Transforming payloads per customer (custom templates, field filtering).
- Non-HTTP destinations (queues, email).
- Billing for webhook usage.
Non-Functional Requirements
Ask about scale and guarantees. We'll assume a platform with 1 million registered endpoints, producing 500 million events a day, with an average of 2 subscribed endpoints per event.
Core Requirements
- Delivery is at least once: every event is eventually delivered to every subscribed, healthy endpoint, or recorded as failed after retries are exhausted.
- Delivery should be fast for healthy endpoints: p95 under 5 seconds from event to first attempt.
- One slow or broken endpoint must not delay deliveries to anyone else.
- Receivers must be able to verify a webhook came from us and wasn't replayed or tampered with.
- Our system must not be usable to attack internal networks (no SSRF).
Below the line (out of scope)
- Strict ordering of events per endpoint. We'll talk about why and what we offer instead.
- Exactly-once delivery. Receivers deduplicate by event ID.
The math: 500M events/day ÷ 86,400 ≈ 5,800 events/s average; plan for 20k/s peaks. With fan-out of 2, that's ~40k HTTP deliveries per second at peak. Now the important part. If a delivery takes 200 ms on average, 40k/s needs 40,000 × 0.2 = 8,000 requests in flight at any moment. But if 5% of endpoints are slow and time out at 10 seconds, those 2,000/s of deliveries alone occupy 2,000 × 10 = 20,000 in-flight slots, more than double everything else combined. Slow endpoints, not traffic, size this system, which is why isolation is a core requirement.
Most of the difficulty in webhooks is that the far end is a stranger's server. It might be down for a week, take 30 seconds to respond, return 200 without processing anything, or point at
169.254.169.254. Design for hostile and broken receivers from the start.