Call back instead of being polled
Third parties poll your API for status, or you poll theirs.
Say it like this
Instead of being polled I push events to a registered URL, signed with HMAC so the receiver can verify them, delivered at least once with backoff, and I expect receivers to ack fast and process asynchronously.
Basic solution
Register a callback URL; the sender POSTs an event when something happens. Sign it and retry with backoff.
Signed, retried delivery with a fast-ack receiver
The sender writes an outbox row with the change and a relay POSTs it signed. The receiver verifies, dedupes, enqueues and acks in milliseconds; a failed delivery is retried with backoff, and after the last attempt the endpoint is marked failing and its owner alerted.
How it works
- The consumer registers an endpoint URL with the provider and chooses which event types it wants. The provider stores the endpoint with a secret that only the two of them know.
- When an event happens, the provider writes an outbox row (event id, type, payload, target endpoint) in the same database transaction as the change itself, so an event can never be lost if the process crashes, and never sent for a change that was rolled back.
- A delivery worker reads the outbox and POSTs the JSON payload to the endpoint. It adds headers carrying the event id, a timestamp, and an HMAC-SHA256 signature computed over the timestamp plus the body using the endpoint's secret.
- The receiver recomputes the signature with its copy of the secret and compares it, rejects anything whose timestamp is older than 5 minutes (which blocks replays of captured requests), returns a 2xx within a few seconds, and then processes the event from its own queue rather than inside the request.
- If the receiver returns a non-2xx status or does not answer in time, the worker schedules a retry with exponential backoff and jitter (roughly 1 minute, 5 minutes, 30 minutes, 2 hours, 12 hours). After the last attempt the endpoint is marked failing and its owner is alerted.
- The receiver deduplicates on the event id, because a retry after a lost acknowledgement delivers the same event a second time.
Direction matters
- As a receiver (provider delivery receipts arriving at the notification system) you own verification, a fast acknowledgement and idempotency. As a sender you own the outbox, the signing, the retries and the health of each endpoint.
Worked example
Provider delivery receipts into the notification system
- 250M notifications per day produce about 300M webhook deliveries from push, SMS and email providers: delivered, bounced, unsubscribed. Average 3,500 per second, 20K per second during a campaign.
- Receiver: the webhook handler verifies the HMAC (about 10 microseconds), writes the raw event to a Kafka topic partitioned by provider message id, and returns 200 in under 20 ms. Processing (updating the delivery row, invalidating a dead token) happens from the topic, so a slow database never makes the provider retry.
- Idempotency: providers retry on timeout; about 0.5 percent of events arrive twice. The handler keeps a Redis SET NX on the provider event id with a 24 hour TTL, so duplicates are dropped before they reach the topic: 1.5M duplicates per day caught.
- Ordering: delivered can arrive before sent-ack from a slow provider. The delivery row records the highest state seen, not the last received.
- Sending our own webhooks (status updates to internal producers): outbox rows published by a relay, 5 retries over 12 hours, endpoints with 50 consecutive failures disabled with an alert. Signature header plus timestamp; receivers reject anything older than 5 minutes to stop replay.
- Capacity: a webhook handler instance acks about 3K requests per second; 8 instances cover the campaign peak, 12 with one zone down.
Variants and when each wins
Provider-signed webhooks (the default)
- The payload is POSTed with an HMAC signature over a timestamp and the body, using a per-endpoint secret. It wins for simple, stateless verification; rotate secrets by accepting both the old and the new one for a window.
Webhooks with a fetch-back
- The payload carries only an event id, and the receiver calls the provider's API to fetch the details. It wins when the payload must never be spoofed or leaked to a misconfigured URL; the cost is an extra round trip per event.
Polling an events endpoint
- The consumer periodically asks the provider for events since a cursor. It wins for consumers that cannot expose an inbound endpoint or sit behind a firewall; it adds latency and load proportional to how often it polls.
Streaming subscriptions
- The consumer holds a persistent connection (server-sent events) or reads a shared Kafka topic. It wins for high-volume internal consumers, where millions of individual POSTs would be wasteful; it needs persistent connections or shared infrastructure.
Recommendation: signed webhooks with event ids and retries for external integrations, with a polling endpoint as the fallback for consumers that cannot receive; a shared log for internal high-volume consumers.
Failure modes
Slow receiver causes provider retries
- The same event arrives three times, and eventually the provider disables your endpoint. The handler processed the event synchronously, including slow database work, before responding, so the provider timed out and retried. Verify the signature, enqueue the raw event, and return 200 within milliseconds; do all the real processing from the queue.
Replayed or forged events
- A bounced status is applied to a delivery from a request that no provider actually sent. The handler never checked a signature, or checked it but ignored the timestamp, so a captured request could be replayed later. Verify an HMAC over the timestamp plus the body, reject anything older than 5 minutes, and compare signatures in constant time so timing differences leak nothing.
Duplicate processing
- A device token is invalidated twice and delivery metrics are double counted. Delivery is at-least-once, so retries after a lost acknowledgement arrive as duplicates, and nothing deduplicated them. Do a SET NX in Redis on the event id with a TTL longer than the provider's retry window, and drop any event that was already seen.
Lost events on the sending side
- A consumer never learns about a change that definitely happened. The webhook POST was attempted directly from the request handler, and the process crashed between committing the change and sending. Write events to a transactional outbox with the change and let a relay deliver them with retries; never send from the request path.
Dead endpoints piling up
- Delivery workers spend most of their time waiting on timeouts. Consumers abandoned their URLs and the workers keep retrying them forever. Circuit-break an endpoint after N consecutive failures, alert its owner, and let them re-enable it with a test delivery once it is fixed.
Interviewer follow-ups
Answer out loud before you open each one.
How does the receiver know a webhook is genuine?
The sender signs the timestamp and body with a shared secret using HMAC-SHA256 and puts the signature in a header. The receiver recomputes it, compares in constant time, and rejects anything whose timestamp is outside a short window, which defeats both forgery and replay.
What should the receiver do inside the request?
As little as possible: verify the signature, dedupe on the event id, write the raw event to a durable queue or table, return 200. Everything that could be slow or fail, like database updates or calls to other services, happens afterwards from the queue.
How do you guarantee the sender never loses an event?
Write the event to an outbox table in the same transaction as the state change, then let a relay deliver it with retries. The outbox makes the event as durable as the change itself; the relay turns it into at-least-once delivery.
How do you handle a consumer whose endpoint is down for a day?
Retry with exponential backoff over a bounded window, then stop and mark the endpoint failing with an alert. Keep the undelivered events so the consumer can replay them from a cursor once fixed, rather than retrying forever against a dead URL.
Connections
The same parts on other clouds
The diagrams above name AWS services as one concrete example. Every part has a close equivalent elsewhere. In an interview, name the role first, such as “a managed Redis cache”, then the product you would pick.
| AWS | Used here as | Google Cloud | Microsoft Azure | Open source and others |
|---|---|---|---|---|
| Amazon EC2 Auto Scaling | Webhook handler, Receipt processor | Compute Engine managed instance groups | Virtual Machine Scale Sets | Kubernetes Deployment with a HorizontalPodAutoscaler, Nomad |
| Amazon MSK (Kafka) | Kafka: receipts | Managed Service for Apache Kafka | Event Hubs (Kafka API) | Confluent Cloud, Redpanda |
| Amazon ElastiCache | Redis dedup | Memorystore | Azure Managed Redis | Redis, Valkey, Memcached |