Skip to content

Design a Webhook Delivery System

A system design interview walkthrough for a webhook delivery system, covering queues, retries with backoff, endpoint isolation, signing and SSRF.

Intermediate23 minUpdated 2 December 2026

Before this: Idempotency, Message Queues, Rate Limiting

"Design a webhook delivery system" is the question where you build the sender's side of an HTTP call you do not control. Your customer's server might be fast, slow, down, misconfigured or hostile. Your job is to deliver an event to it, reliably, without letting any one customer's endpoint hurt anyone else.

The interviewer is looking for a particular instinct: the receiver is untrusted and unreliable, so every design choice is about containing that. Retries must not hammer a struggling endpoint. A slow endpoint must not block fast ones. A dead endpoint must not cost you money forever. And the callback URL, which a customer types in, must not be a way to attack your own network.

The reliability vocabulary comes from idempotency and message queues. This page applies it to a delivery pipeline.

Clarify the requirements

Functional requirements:

  1. A customer registers an endpoint URL and chooses the event types it wants (invoice.paid, order.shipped).
  2. When an event happens, the platform sends an HTTP POST with a JSON payload to every subscribed endpoint.
  3. A 2xx response within a timeout means delivered. Anything else is a failure and is retried.
  4. Customers can see delivery attempts and responses, and replay a past event.
  5. Each request is signed so the receiver can verify it came from us.
  6. After repeated failures an endpoint is disabled and the customer is notified.

Out of scope, said aloud: building the events themselves (other services emit them), a customer-facing UI beyond an API for logs, and transformations of the payload.

Non-functional requirements:

  • At-least-once delivery. An event is delivered one or more times, never silently dropped. Exactly-once across an HTTP call is not achievable, so we say that plainly.
  • Isolation. A customer's slow or failing endpoint must not delay anyone else's webhooks.
  • Timeliness. Healthy endpoints receive events within a few seconds of the event.
  • Politeness. Retries back off, and we cap concurrency per endpoint so we cannot take down a small customer.
  • Security. Signed payloads, HTTPS, and no way to make us call internal addresses.

Estimate the scale

Assume 1 million merchant accounts generating 50 million events a day, with each event subscribed by an average of two endpoints. Payloads are about 2 KB.

Deliveries: 50M × 2 = 100 million a day ÷ 86,400 s ≈ 1,157 per second, about 3,500 per second at peak.

HTTP attempts: suppose 10% of first attempts fail and the failures average three more attempts. That is 1 + 0.1 × 3 = 1.3 attempts per delivery, so 130M ÷ 86,400 ≈ 1,500 attempts per second, and about 4,500 at peak.

Concurrency: at about 300 ms per call, 1,500 × 0.3 s = 450 requests in flight on average. Slow endpoints change this a lot: if 1% of attempts hang until a 10-second timeout, that is 15 per second × 10 s = 150 more connections held open for nothing. Timeouts are a capacity input.

Storage: events at 50M × 2 KB = 100 GB a day; the attempt log at 130M × 200 B = 26 GB a day. Keeping 30 days for replay is about 3 TB of events and 0.8 TB of logs.

Log reads: merchants checking delivery logs, say 500,000 a day, is about 6 per second. Negligible.

"About 1,200 deliveries a second is small. The sizing that matters is retries and held connections: slow endpoints cost the most. The design problem is not throughput, it is isolation, backoff and containing a misbehaving receiver."

The capacity estimator reproduces the delivery rate. The storage field there covers the payload per delivery, which our design avoids with a shared event store.

API and data model

POST /v1/endpoints              { url, eventTypes[], secret? }      -> { endpointId, signingSecret }
PATCH /v1/endpoints/{id}        { url?, eventTypes?, enabled? }
GET  /v1/events/{eventId}/deliveries                                 -> attempts[]
POST /v1/events/{eventId}/replay { endpointId }

Internally, the producing service does not call an HTTP API: it writes the event in the same database transaction as the business change, and a relay publishes it.

event      (event_id PK, account_id, type, payload, created_at)         // stored once
endpoint   (endpoint_id PK, account_id, url, secret, event_types, status, consecutive_failures)
delivery   (delivery_id PK, event_id, endpoint_id, status, next_attempt_at, attempts)
attempt    (delivery_id, n) -> status_code, latency_ms, response_snippet, error

The non-obvious choice is one delivery row per (event, endpoint). It carries its own retry clock and state, so a failing endpoint's backlog is just its own rows, and a replay is a new delivery row for an old event.

High-level design

We simulate the spine: event sources feed an event API, which writes to a delivery queue, and a pool of delivery workers sends the calls and logs each attempt.

Events pass an API into a queue with retries and a dead letter limit, and delivery workers send them and log each attempt.event sourcesevent apidelivery queuedelivery workersattempt log
Events pass an API into a queue with retries and a dead letter limit, and delivery workers send them and log each attempt.
  • The event API fans each event out to one queued message per subscribed endpoint.
  • Delivery workers take messages, call the endpoint and write every attempt to an attempt log.
Describe this diagram

Components

  • event sources (Client)
  • event api (Service)
  • delivery queue (SQS queue)
  • delivery workers (Service)
  • attempt log (DynamoDB)

Connections

  • event sources sends to event api
  • event api sends to delivery queue
  • delivery queue sends to delivery workers
  • delivery workers sends to attempt log

Run it, then try shrinking the worker pool or raising the load. Watch queue age: a delivery system is healthy when events leave the queue about as fast as they enter.

The write path: the business service commits its change and an outbox row together (see the outbox lesson). A relay reads the outbox, looks up subscribed endpoints and creates one delivery per endpoint.

The send path: a worker leases a delivery, signs the payload, makes the HTTP call with a short timeout and records the result. On success it marks the delivery done. On failure it schedules the next attempt.

The interesting problem: retries without a retry storm

When delivery fails, what you do next decides whether a small outage stays small. Three designs:

Approach A: send inline from the producer

The service that creates the event calls the endpoint during the request, and retries on failure.

Good: the simplest thing, with no new components.

Bad: the customer's slow server now slows your own API. A failing endpoint fails your business request, or you drop the event. Retries live in memory, so a deploy loses them.

Approach B: one shared queue with immediate retries

Put deliveries on a queue and retry failures by putting them back.

Good: durable, and the producer is decoupled.

Bad: head-of-line blocking. One merchant's endpoint that hangs for 10 seconds ties up workers, and every other merchant's events wait behind it. Immediate retries multiply the load on an endpoint that is already struggling, which is exactly when it needs relief.

Approach C: per-endpoint isolation, backoff with jitter, and a circuit breaker

Keep the durable queue and add three controls:

  • Per-endpoint concurrency limits. At most, say, 5 requests in flight to any one endpoint. Extra deliveries wait in that endpoint's own backlog, not in the shared worker pool.
  • Exponential backoff with jitter. Retry after about 5 s, 30 s, 5 min, 30 min, 2 h, 6 h, 12 h and 24 h: 9 attempts in all over roughly 45 hours. Randomize each delay by up to 20% so a thousand failed deliveries do not all retry at the same second.
  • A circuit breaker per endpoint. After a run of failures, stop sending live traffic and probe occasionally. The circuit breaker pattern protects the receiver and your workers together. When the probe succeeds, drain the backlog gradually.
Conceptual diagramlimit 5 per endpoint2xxerror or timeoutafter 9 attemptsEventDelivery rowsWorker poolCustomer endpointDoneRetry with backoff and jitterDead letter and disable
Diagram, as text
  • Event leads to Delivery rows
  • Delivery rows leads to Worker pool
  • Worker pool leads to Customer endpoint (limit 5 per endpoint)
  • Customer endpoint leads to Done (2xx)
  • Customer endpoint leads to Retry with backoff and jitter (error or timeout)
  • Retry with backoff and jitter leads to Delivery rows
  • Retry with backoff and jitter leads to Dead letter and disable (after 9 attempts)

This is the answer to aim for. Each endpoint becomes its own small, bounded queue, so one bad receiver can only hurt itself. See design a message queue for how the underlying queue handles visibility timeouts and dead letters.

The second decision: delivery guarantees and ordering

Be explicit about the contract, because receivers build on it:

  • At-least-once. The receiver may see the same event twice, for example when it processed the event but its 2xx response was lost. So every payload carries a stable event_id, and the receiver is told to deduplicate on it. This is the idempotency-key idea, with the receiver playing the server.
  • No ordering guarantee. With retries and parallel workers, order.updated can arrive before order.created. Ordering within one endpoint is expensive, since one stuck event would block all later ones. Instead, include a monotonically increasing sequence or a created_at and a way to fetch current state (GET /v1/orders/{id}). Tell receivers to treat the webhook as a notification: on receipt, fetch the latest resource.
  • Sign everything. Compute an HMAC-SHA256 over timestamp + "." + body with the endpoint's secret and send both in headers. The receiver recomputes it and rejects timestamps older than about five minutes, which defeats replays. Support two secrets during rotation.

If a customer truly needs order, offer an opt-in "ordered endpoint" that sends events one at a time, and say the price: a single stuck event stalls the stream until it succeeds or is skipped.

Bottlenecks and failures

SSRF. The customer chooses the URL, so they can point it at http://169.254.169.254/ (a cloud metadata service) or at an internal admin server. Resolve the hostname yourself, reject private, loopback and link-local address ranges after DNS resolution, connect to the resolved IP (to defeat DNS rebinding), disable redirects or re-validate each hop, and run workers in a network segment with no route to anything sensitive. The application security lesson covers this attack in detail.

A giant backlog. When a large customer's endpoint is down for six hours, their deliveries pile up. Because they sit in per-endpoint backlogs with a rate limit, they cannot flood the shared pool when the endpoint returns. Release them at a controlled rate so you do not knock the endpoint over again.

Slow receivers. A 10-second timeout can hold 150 connections open at our sizing. Use a short timeout (5 to 10 seconds), treat a timeout as failure and do not read more than a small prefix of the response body (about 1 KB is enough for the log).

Dead endpoints cost money. After 9 failed attempts a delivery is dead-lettered. After, say, 3 days of consecutive failures, the endpoint is disabled and the customer is emailed. Without this, a forgotten test URL costs retries forever.

What if the queue is down? Events still commit in the producer's database with their outbox row, and the relay publishes when the queue returns. Nothing is lost, only late.

What if our workers are down? The queue holds the backlog. Alert on the age of the oldest ready delivery, not on error counts, since nothing is "failing" while it waits.

Trade-offs to name aloud

  • At-least-once over exactly-once: duplicates are possible, so receivers must deduplicate.
  • Unordered delivery: keeps the system fast and isolated, and pushes "fetch the latest state" onto the receiver.
  • Per-endpoint limits: protects customers and the shared pool, but a large customer's backlog drains slower.
  • Long retry window: survives a day-long customer outage, and costs storage and a larger backlog.
  • Short timeouts: frees workers, and may mark a legitimately slow receiver as failing.

What interviewers listen for

  • A working answer: an outbox or queue, workers that call the URL, retries with backoff, a log of attempts and a signature.
  • A strong answer: sizes the retries and held connections, isolates each endpoint, adds jitter and a circuit breaker and states the at-least-once and no-ordering contract.
  • A standout answer: handles SSRF after DNS resolution, honors Retry-After, disables dead endpoints, supports signature rotation with timestamps against replay and offers replay from the event store.

Check your understanding

Common mistakes

Sending webhooks from the request that caused them. A slow customer endpoint then slows your own API, and a restart loses the retries. Always go through a durable queue.

Promising exactly-once. You cannot. State at-least-once, include an event id and tell receivers to deduplicate.

Retrying immediately and forever. It punishes the endpoint that is already failing and wastes your capacity. Use backoff, jitter, a cap and an off switch.

One queue for all customers. A single bad endpoint becomes everyone's latency problem. Isolate per endpoint.

Validating the URL as a string. Hostnames can point anywhere, including your internal network. Validate the resolved address.

Guaranteeing order without paying for it. Strict ordering stalls a stream behind one failed event. Offer notifications plus fetch-latest instead, and be explicit when ordering is opt-in.

Practice

A large customer's endpoint was down for 8 hours and has 2.4 million deliveries waiting. It just came back. What do you do so the recovery does not knock it down again?

Write your own answer first, on paper or in a note. Then compare.

Show a hint

The backlog is yours to release. Think about rate, order and the circuit breaker's probe.

Show a strong answer

Do not flush the backlog. 2.4 million deliveries released at once is more traffic than the endpoint ever handled. Keep the per-endpoint concurrency limit and add a rate ceiling that ramps up: start at 50 per second, double every minute while error rates stay low, and stop at the customer's configured maximum.

Let the circuit breaker lead. The breaker is half-open: send a few probe deliveries first. If they succeed, close it and start the ramp. If they fail, stay open and keep backing off.

Prioritize the newest events, or at least interleave them with the old ones. Receivers usually care more about a payment that just happened than one from 8 hours ago, and a recent event may supersede an old one.

Tell the customer. Show the backlog size and estimated drain time in their dashboard, and let them pause or throttle delivery themselves.

The pattern worth keeping: recovery traffic is a load spike you create. Ramp it, probe first and keep the cap in your hands.

A receiver complains: it processed the same invoice.paid event twice and issued two receipts. Whose bug is it, and what do you change?

Write your own answer first, on paper or in a note. Then compare.

Show a hint

Walk through how a duplicate legitimately happens in an at-least-once system, then decide what the platform owes the receiver.

Show a strong answer

It is a shared problem with a clear contract. The receiver can respond with 2xx after doing the work, and the response can be lost or arrive after our timeout. We must treat that as a failure and retry, so a duplicate is expected behavior, not a platform fault.

The receiver fixes its handler. It should record each event_id it has processed (a unique constraint is enough) and skip repeats, in the same transaction as the receipt it creates.

The platform helps by being consistent. The event_id must be identical on every attempt and on replays. Send an attempt number header as well, so the receiver can see it is a retry. Document the guarantee prominently, with sample dedupe code.

Reduce needless duplicates. Do not set the timeout lower than the receiver's normal processing time. Many duplicates come from timeouts that are too tight.

The pattern worth keeping: in at-least-once systems, give every message a stable id, and put the deduplication on the side that performs the side effect.

Key takeaways

  • The receiver is unreliable and untrusted. Every decision follows from containing it.
  • At-least-once with a stable event id is the honest contract. Tell receivers to deduplicate.
  • Isolate each endpoint with its own backlog and concurrency limit, so one bad receiver hurts only itself.
  • Back off with jitter, cap attempts, use a circuit breaker and disable dead endpoints.
  • Do not promise ordering. Send notifications and let receivers fetch the latest state.
  • Defend against SSRF by validating resolved addresses, and sign every request with a timestamp.

Further reading

  • Marc Brooker, "Exponential Backoff And Jitter" (AWS Architecture Blog, 2015): why jitter matters and which variant performs best.
  • Amazon Web Services documentation, "Amazon SQS dead-letter queues" and "visibility timeout": the queue primitives behind retry and dead lettering.
  • H. Krawczyk, M. Bellare and R. Canetti, RFC 2104 "HMAC: Keyed-Hashing for Message Authentication" (1997): the signature scheme used to sign payloads.
  • OWASP, "Server-Side Request Forgery Prevention Cheat Sheet": defenses for any feature that fetches a user-supplied URL.

Check yourself

3 questions in this lesson. Answer each once to complete it.

Practice this

Lessons in this track