| @@ -0,0 +1,35 @@ | |||
| 1 | + | # System Design Interview: Designing a Webhook Delivery System | |
| 2 | + | ||
| 3 | + | Platforms like Stripe and GitHub notify customers by POSTing events to URLs the customer registers. Designing that reliably is a good interview question. | |
| 4 | + | ||
| 5 | + | ## Requirements | |
| 6 | + | ||
| 7 | + | - Customers register endpoints and choose event types. | |
| 8 | + | - Every event is delivered at least once, even if the customer's server is down for hours. | |
| 9 | + | - One slow or broken endpoint must not delay everyone else. | |
| 10 | + | ||
| 11 | + | ## Flow | |
| 12 | + | ||
| 13 | + | 1. When a business event happens, the producing service writes it to an **outbox** table in the same transaction as its own change, so events are never lost. | |
| 14 | + | 2. A relay publishes events to a queue. A fan-out service looks up subscriptions and creates one **delivery** record per (event, endpoint). | |
| 15 | + | 3. Delivery workers POST the payload with a timeout (say 10 s). A 2xx means done; anything else schedules a retry. | |
| 16 | + | ||
| 17 | + | ## Retries | |
| 18 | + | ||
| 19 | + | Exponential backoff with jitter (1 min, 5 min, 30 min, 2 h ... up to ~3 days), then mark the delivery failed and alert the customer. Store attempts so customers can see history and trigger a manual redelivery. | |
| 20 | + | ||
| 21 | + | ## Isolation | |
| 22 | + | ||
| 23 | + | Keep a queue (or a rate-limited lane) **per endpoint** or hash endpoints into many queues, and cap concurrency per endpoint. Otherwise one endpoint that hangs for 10 s per request ties up all workers. Disable endpoints that fail for days. | |
| 24 | + | ||
| 25 | + | ## Security | |
| 26 | + | ||
| 27 | + | - Sign each payload with an HMAC of the body and timestamp using a per-endpoint secret; receivers verify the signature and reject old timestamps to stop replays. | |
| 28 | + | - Resolve and block private IP ranges before connecting, to avoid SSRF into your own network. | |
| 29 | + | ||
| 30 | + | ## Receiver expectations | |
| 31 | + | ||
| 32 | + | Document that delivery is at-least-once and possibly out of order: include an event ID for dedup and a timestamp or version so receivers can ignore stale updates. | |
| 33 | + | ||
| 34 | + | --- | |
| 35 | + | *Disclosure: I work on [Linkjob AI](https://www.linkjob.ai/), an AI job interview assistant.* | |
linkjobai / System Design Interview: Designing a Webhook Delivery System
Last active 5 days ago
Interview prep notes
linkjobai revised this gist 5 days ago · e221fb6
1 file changed, 35 insertions