Video in progress

Strong Middle 🏗️ System design

How do you design a system that sends webhooks to customers' servers?

Events are written to a queue, and workers deliver them separately for each customer: with a signature (HMAC), a short timeout, retries with exponential backoff over several days, and a stored delivery history the customer can view.

📖 Answer

With webhooks, the receiving server isn't under your control: it's slow, sometimes down, sometimes returns 200 and actually does nothing. The system has to tolerate that.

Queue and isolation. The event first goes into the DB (a deliveries table) and the queue. Workers are partitioned by customer: if one customer's server doesn't respond for 30 seconds, other customers' webhooks shouldn't wait. A parallel request limit per customer.

Use a short timeout when sending (5–10 s). 2xx — success. 4xx/5xx/timeout — a retry schedule: 1 minute, 5, 30, 2 hours, ... up to 3 days. Then FAILED and an email to the customer. You also need to automatically disable an endpoint that has been failing for a long time.

Signature: the customer must be able to verify that the request really came from you:

String payload = timestamp + "." + body;
Mac mac = Mac.getInstance("HmacSHA256");
mac.init(new SecretKeySpec(secret, "HmacSHA256"));
String sig = HexFormat.of().formatHex(mac.doFinal(payload.getBytes(UTF_8)));
// header: X-Signature: t=1730620800,v1=<sig>

The timestamp goes into the signature, so replaying an old request doesn't work — the customer rejects anything older than 5 minutes.

Duplicates and order. Because of retries, the customer may receive an event twice — give every event a stable id and write "handle it idempotently" in the docs. Order isn't guaranteed; so put created_at or a version in the payload, or send only a "what changed" signal and let the customer fetch the full state from the API.

Security. A URL the customer enters may point at an internal network (169.254.169.254, 10.x) — that's SSRF. Resolve the IP and block internal ranges.

Give the customer a delivery log and a "resend" button — the questions that reach support drop a lot.