Design a Delayed Webhook Delivery Service
System DesignModel answerLast updated
Design a system that accepts a target URL, a future timestamp, and a JSON payload, then reliably delivers that payload via HTTP at the scheduled time.
Delayed Webhook Delivery Service
Your task is to design a backend service that lets callers schedule an outbound HTTP delivery for a future point in time. Callers submit a request body like this:
{
"url": "https://example.com/api",
"timestamp": "2026-07-05T12:30:00Z",
"data": { "...": "..." }
}
The service persists the request, waits until the wall-clock time matches timestamp, then POSTs data to url. The caller's own server is not involved again until that delivery arrives.
What to cover
- The API clients use to submit (and optionally manage) scheduled deliveries
- How scheduled deliveries are stored durably
- How the system efficiently finds and dispatches deliveries that are due, at scale, without double-delivery
- What happens when a delivery fails — the target returns an error, is slow, or is unreachable
- How the system recovers when one of its own components crashes mid-flight
- Any security measures around which URLs the service is allowed to call
Constraints and given facts
- Each incoming request contains exactly three fields: a URL, an ISO 8601 UTC timestamp, and an arbitrary JSON payload.
- The service is responsible for making the outbound call at the scheduled time.
What is NOT given — clarify or state assumptions
The following are deliberately left open. In an interview you would ask about them; here, state your assumptions explicitly before designing:
- The HTTP method, headers, and timeout for the outbound call
- Required delivery precision (sub-second, a few seconds, within a minute?)
- Whether early delivery is ever acceptable
- How to handle timestamps in the past or far in the future
- What counts as a successful delivery, and how many retries are appropriate
- Expected submission and delivery throughput at peak load
- Whether many deliveries can share the same timestamp ("thundering herd")
- Whether clients need to cancel, update, or look up a scheduled delivery, or receive a failure notification
- Whether callers are trusted and whether any URL on the internet is a valid target
Hints
Hint 1
Before drawing any boxes, nail down delivery precision and throughput — a service that needs sub-second accuracy with 10k deliveries/sec looks very different from one that tolerates a 5-second window at 100/sec.
Hint 2
Think about how you index scheduled deliveries for efficient polling. A naive 'scan everything' query won't survive at scale — consider what a time-bucketed structure or a priority queue in a durable store buys you.
Hint 3
At-least-once delivery is much easier to guarantee than exactly-once, but it shifts the deduplication burden to receivers. Be explicit about which guarantee you're offering and what a receiver needs to do to be safe.
Model answer
Medium Try it yourself first — then compare your approach, complexity and edge cases.
Step 1 — Clarify before designing
State assumptions up front; a design without them is incomplete.
- Outbound call: HTTP POST,
Content-Type: application/json, body isdata, 10-second timeout per attempt. - Precision: delivery within 5 seconds of
timestampis acceptable; early delivery is not. - Past timestamps: reject at submission time with a 400. Timestamps more than 1 year out are also rejected.
- Success: any 2xx response from the target counts. Non-2xx and timeouts trigger retries.
- Retry policy: up to 5 attempts with exponential backoff (5 s, 25 s, 2 m, 10 m, 45 m). After exhausting retries the delivery is marked failed and the client can optionally receive a webhook failure notification.
- Scale: assume ~1,000 submissions/sec and ~1,000 deliveries/sec at peak, with occasional bursts where thousands share the same minute.
- Client operations: clients can cancel a pending delivery or look up its status by ID.
- Security: callers are authenticated; target URLs are validated against a blocklist of RFC-1918 ranges and internal hostnames to prevent SSRF.
API
POST /schedules
Body: { "url": "...", "timestamp": "...", "data": { ... } }
Response 201: { "id": "sch_abc123", "status": "pending" }
GET /schedules/{id} → current status + delivery attempts
DELETE /schedules/{id} → cancel if still pending
Submission is idempotent when the caller provides a client_request_id header; the service returns the same id for duplicate submissions within a 24-hour window.
Storage
Each scheduled delivery is a row in a relational database (Postgres works well here):
| Column | Type | Notes |
|---|---|---|
| id | UUID | primary key |
| url | text | validated at write time |
| scheduled_at | timestamptz | indexed |
| payload | jsonb | |
| status | enum | pending / delivering / delivered / failed |
| attempt_count | int | |
| next_attempt_at | timestamptz | indexed, used for retries |
| locked_by | text | worker ID |
| locked_until | timestamptz | lease expiry |
The two indexes that matter are on (status, next_attempt_at) — the poller's query hits exactly this.
For very high throughput, partition the table by scheduled_at date or shard by id % N so multiple database nodes share the write load.
Finding and dispatching due work
A fleet of poller workers runs this loop every few seconds:
UPDATE scheduled_deliveries
SET status = 'delivering',
locked_by = :worker_id,
locked_until = NOW() + INTERVAL '60 seconds'
WHERE status = 'pending'
AND next_attempt_at <= NOW()
AND (locked_until IS NULL OR locked_until < NOW())
RETURNING *
LIMIT 50;
The UPDATE … RETURNING pattern is an atomic claim — no two workers pick the same row. Each worker then fans the claimed rows out to a thread pool (or pushes them onto an internal queue) for actual HTTP dispatch. This decouples slow outbound calls from the polling loop.
For a thundering-herd scenario (thousands of rows share the same minute), the LIMIT 50 per worker, combined with horizontal scaling of workers, naturally spreads the load. Workers can also be scaled independently of the API tier.
Delivery and retries
Each HTTP call runs with the 10-second timeout. On success, the row is marked delivered. On failure:
- Increment
attempt_count. - If
attempt_count < 5, compute the next backoff delay and write it tonext_attempt_at, resetstatustopending. - If
attempt_count == 5, markstatusasfailedand optionally enqueue a failure notification to the client.
Backoff uses 5 * 5^(attempt_count - 1) seconds with ±10% jitter to avoid retry storms when a target comes back online.
Crash recovery
The lease (locked_until) is the safety net. If a worker crashes mid-delivery, the row stays in delivering state but the lock expires after 60 seconds. The next poller sweep picks it up and retries. This guarantees at-least-once delivery — clients should be told to handle duplicate POSTs by treating the id as an idempotency key.
The API servers are stateless, so they can be restarted freely. The database is the source of truth; replicate it synchronously (Postgres streaming replication or a managed equivalent) so a single node loss does not lose scheduled work.
Isolation from slow targets
- Each outbound call runs in a worker thread pool sized separately from the poller. A slow target blocks one thread, not the whole system.
- Circuit-break per domain: after N consecutive failures to the same host within a window, back off that host entirely for a few minutes before retrying. This prevents one misbehaving endpoint from consuming all worker threads.
- Enforce the SSRF blocklist at dispatch time, not just at submission, in case DNS rebinding is a concern.
Observability
Key metrics to expose:
- Delivery lag:
delivered_at - scheduled_atas a histogram. Alert if p95 exceeds the precision SLA. - Queue depth: rows in
pendingstate withnext_attempt_atin the past — a rising number means workers can't keep up. - Retry rate and failure rate per target domain.
- Worker pool saturation.
Common mistakes to avoid
- Polling with a full table scan — always query on an indexed
(status, next_attempt_at)pair, neverSELECT * WHERE status = 'pending'. - No lease / optimistic locking — without a claim mechanism, multiple workers deliver the same payload simultaneously.
- Synchronous delivery in the API handler — the submission response must return before the scheduled time; never attempt delivery at write time.
- Ignoring SSRF — an unauthenticated service that POSTs to arbitrary URLs is a serious internal-network exposure.
- Promising exactly-once — it's extremely hard to achieve across crashes and retries; at-least-once with client-side idempotency keys is the practical answer.