Skip to the page

gRPC, real-time APIs and webhooks · senior

Webhooks: delivery, retries and signatures

A webhook is at-least-once delivery over HTTP. Senders use an outbox, per-endpoint queues, backoff and a signature. Receivers answer fast, verify the signature on the raw body and de-duplicate by event id.

The notes

What you must know

  • Exactly once is impossible over HTTP: when a request times out, the sender cannot know if it was processed. Deliver at least once and say so in the docs.
  • Receiver: check the signature first, store the event, answer 2xx fast, process in the background, and de-duplicate by event id with a unique constraint.
  • Sender: the same event id and payload on every retry, exponential backoff with jitter, a documented timeout (about 10 to 15 seconds), a log of every attempt, and a dashboard and resend button for partners.
  • Capture with an outbox table written in the same database transaction as the change. A relay publishes to a queue. No event without a committed change, and none lost in a crash.
  • Isolate endpoints: per-endpoint queues or concurrency limits and a circuit breaker, so one slow merchant fills only its own lane. After days of failures, mark the endpoint failing, email the merchant and keep events for replay.
  • Signing: HMAC-SHA256 over the id, timestamp and raw body with a per-endpoint secret. Verify with a constant-time comparison, reject timestamps older than about 5 minutes (replay), and accept several signatures during secret rotation.
  • Verify on the raw bytes. Parsing and re-serialising JSON changes spacing and key order, so the HMAC will not match. Many frameworks parse first, so capture the raw body.

The red pen

Common traps: mistake → fix

  • Mistake: A webhook is sent exactly once

    Fix: It is at least once. Receivers must handle duplicates.

  • Mistake: I can compare signatures with ==

    Fix: Use a constant-time comparison to avoid timing attacks.

  • Mistake: I can verify the signature on the parsed JSON

    Fix: Spacing and key order change. Use the raw bytes.

Easy to hard

Questions interviewers ask, easy to hard

  1. Why are webhooks at-least-once and what must a receiver do about it?
  2. A partner got the same webhook three times. How do you explain it from the logs?
  3. How do you sign and verify a webhook? Why include a timestamp?
  4. Why use an outbox for webhook events?
  5. Design webhook delivery for 5,000 merchants where some endpoints are slow or down.

Practise

Practise with these questions

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview