Skip to content
Tech Interview Prep
Technical interview guide

Webhooks & Asynchronous API Integration

Handling work that can't complete within a single request/response cycle: inbound webhooks and long-running async job APIs.

Minutes to read
4
Practice MCQs
25
Interview Q&A
25
Edition
v4
Editorial status
Reviewed

Scope: HTTP Semantics RFC 9110 and OpenAPI Specification 3.2.

Overview

Curated: · Written: · Reviewed:

Webhooks & Asynchronous API Integration

In one line

A webhook is the provider POSTing an event to a consumer URL. The consumer must be an idempotent receiver that verifies signatures on the raw body, and the provider must run a retrying, per-endpoint delivery queue with a dead-letter path. Reach for webhooks across an organisational boundary where the consumer can expose a public endpoint. Pair them with a polling API so consumers can reconcile missed events.

Key definitions

  • At-least-once: a delivery may repeat, because the sender cannot tell a lost response from a lost request, so it retries on any failure without a 2xx.
  • Idempotent receiver: a repeat of the same event id produces no second effect.
  • Raw-body signature: HMAC-SHA256 over the exact bytes received, checked before parsing.
  • Timestamp tolerance: a signed timestamp outside a window (300 s in the Stripe-style example) is rejected, which blocks replay of captured requests.
  • Dead-letter queue (DLQ): where an event goes after the retry window, with an alert and a replay path.
  • SSRF: the sender is induced to call internal addresses through a consumer-supplied URL.

Formulas and complexity

The example retry policy's window:

30+60+300+1800+3600+21600=27390 s≈7.6 h30+60+300+1800+3600+21600=27390\ \text{s}\approx 7.6\ \text{h}

Sizing the pool: in-flight deliveries are bounded by workers, so with a 10 s timeout and 50 workers, 5 hung endpoints hold the whole pool.

How it works

  1. Emit: the producer writes a delivery record durably and returns. It never delivers inline.
  2. Partition: records route to the partition owned by the endpoint, so one worker delivers them in order.
  3. Sign and send: the worker signs the exact bytes on the wire with a timestamp and sends with a hard timeout.
  4. Classify: 2xx is done. Timeout, connection error, 5xx and 429 retry with exponential backoff and jitter. Other 4xx is permanent.
  5. Receive: the consumer verifies the raw body, parses, inserts the event id under a unique constraint, returns 2xx, then processes asynchronously.
2xx timeout, 5xx, 429 other 4xx or window exhausted Event written to durable queue Worker for endpoint partition Sign raw bytes plus timestamp, send with hard timeout Response Done Retry with backoff and jitter Dead-letter queue, alert, replay

When to use and when not to

SituationWebhooks?Better fit
Consumer is another organisation with a public endpointYesn/a
Both systems are yoursNoDurable queue or broker
Consumer is behind NAT or a firewallNoPull API or polling
You need replay or backfillOnly if you build itRetained log
You need strict orderingNoSerialised per-consumer queue, accepting the latency coupling
Low volume, latency tolerantOften noPolling

Traps interviewers probe

  1. Acknowledging before the event is durable. Returning 200 and buffering in memory loses events on SIGTERM or SIGKILL, and the sender sees success. Fix: write the event durably, then return 2xx.
  2. Verifying re-serialised JSON. The framework encoder changes bytes, so digests disagree on some events. Fix: verify the raw bytes read off the socket, then parse.
  3. Deduplicating on the body hash or attempt headers. Retries change attempt counters and timestamps inside the body, so hashes differ. Fix: key deduplication on the provider's event id, and make the business effect idempotent under that key.
  4. Recording the event as processed before the effect commits. A crash between the two leaves the event marked done and the order unpaid. Fix: record the processed marker in the same transaction as the effect.
  5. Checking private addresses once at registration. DNS rebinding and redirects move the target after the check. Fix: re-validate the resolved address at request time, and after every redirect.

Interview tips

Opening: Delivery is at-least-once, so the consumer must be idempotent. The provider signs, retries with backoff and jitter, isolates endpoints, dead-letters and offers replay.

Expected follow-ups:

  • The endpoint is down for six hours: retries over a bounded window, a per-endpoint circuit breaker, DLQ, replay.
  • The consumer registers 169.254.169.254: SSRF, re-checked at delivery time.
  • Why not Kafka: you cannot hand a broker to a stranger's account.
  • Secret rotation: dual-sign grace period, accepting old and new signatures.
  • Ordering: not guaranteed. Carry a timestamp or sequence number and ignore older events.

30-second outline:

  • Guarantee: at-least-once with consumer idempotency. Exactly-once delivery is not available.
  • Sender: enqueue durably, partition per endpoint, sign raw bytes with a timestamp, hard timeout, classify, backoff with jitter, circuit-break, dead-letter, replay.
  • Receiver: verify the raw body in constant time, insert the event id under a unique constraint, return 2xx quickly, process asynchronously.
  • Security: HMAC with timestamp tolerance, SSRF checks at request time, no response bodies returned to the consumer.

Feedback on this overview

Log in free to save your progress and keep bookmarks and notes for a quick revision before your interview.