28 September, 2018, 04:57

31°c , California

Parquet Courts on Resisting Nihilism & Why Tourism in Dubai is booming the world.

Parquet Courts on Resisting Nihilism & Why Tourism in Dubai.

Also Popular
 

Article

Webhooks That Behave: Idempotency, Signatures and Replays

  • 21K
  • 12

Webhooks look simple: an event happens, a request arrives, the receiver does the work. In production, that tidy story becomes a sequence of retries, duplicates, late deliveries and the occasional malicious replay. Designing idempotent webhooks is less about adding a retry loop and more about making every delivery safe to receive more than once. Signatures, replay handling and dead-letter queues are not separate concerns; together they form the contract between producer and consumer.

Start with an idempotency key that belongs to the event

The consumer should not invent a key from the request body at the last moment. The producer should send a stable event identifier, ideally in a header and in the payload, and keep it unchanged across retries. Store that key alongside the processing outcome in a durable table with a unique constraint. If the insert fails because the key already exists, return the same response as the first successful attempt rather than doing the work again. This sounds obvious, but the awkward cases matter: two workers receiving the same event at once, a crash after writing the key but before completing the side effect, or a replay months later. Use a transaction or a short lock around the idempotency record, and choose a retention period longer than your retry and replay windows. A key scoped only to a timestamp or request hash will eventually collide or drift.

Verify signatures before you trust the payload

A signature tells you who sent the request and whether the body was altered in transit. It does not prove the event is new. Sign the raw request body, a timestamp and a key identifier, then compare the result using a constant-time function. Reject requests whose timestamp is outside a small window, and include the event identifier in the signed material so a valid signature cannot be moved to a different event. Keep secrets out of logs, support rotation with overlapping key identifiers, and make signature failures visible without leaking whether a key exists. Many teams verify signatures only at the edge, then pass a trusted header downstream. That is fine if the internal hop is genuinely trusted; otherwise, the consumer should verify too. If you want to dig deeper, The Varsity Jacket shop is a useful place to start.

Replays are a recovery tool, not just an attack

Security teams rightly worry about replay attacks, but controlled replays are also how you recover from a missed event or a bug in a consumer. The producer should offer an auditable replay path: authorised operators, a clear scope, a reason, and a record of which events were resent. Consumers should treat a replay exactly like any other duplicate and rely on idempotency rather than assuming each delivery is new. Avoid building replay as a bulk database copy with no throttling. Rate-limit it, tag replayed events so downstream systems can distinguish them, and make sure the same dead-lettered event can be replayed after a fix without creating a second side effect.

Dead letters need a route back into the system

A dead-letter queue is not a bin. It is a holding area for messages that have exhausted automatic retries, and it needs ownership, context and a process for recovery. Retry with exponential backoff and jitter, cap the attempts, then move the event to the dead-letter store with the original headers, body, attempt count, first-seen time and last error. Alert on growth and age, not just count. When an incident is fixed, replay deliberately and verify the result. Poison messages should be quarantined with enough detail to debug, but be careful with personal data and secrets in stored payloads. Set a retention policy and document who can inspect, delete or replay entries.

Make observability part of the contract

You cannot operate idempotent webhooks by hope. Track accepted events, duplicate hits, signature failures, retry counts, dead-letter depth and the age of the oldest dead-lettered event. Use a correlation identifier that survives retries and appears in logs on both sides. Monitor the health of the idempotency store, because a slow unique index can turn a duplicate-safe endpoint into a bottleneck. Prioritise alerts on dead-letter age, not just depth. Build runbooks for the common failures: a secret rotation gone wrong, a consumer deploying a bug that rejects every payload, or a replay that accidentally targets the wrong environment.

A short checklist before launch

  • Event IDs are stable across retries and stored with a unique constraint.
  • Signatures cover the raw body, timestamp and event identity, and old timestamps are rejected.
  • Duplicate deliveries return the original result rather than repeating side effects.
  • Retries use backoff and jitter, with a cap before dead-lettering.
  • Dead-letter entries carry enough context to debug without exposing secrets.
  • Replays are authenticated, auditable, rate-limited and safe to run twice.
  • Dashboards and alerts cover duplicates, signature failures, retry pressure and dead-letter age.

None of this is glamorous, but it is the difference between a webhook integration that mostly works and one you can trust during an incident. Recognise that every delivery may be repeated, every signature is necessary but not sufficient, and every dead letter is work waiting to be finished. That mindset turns a fragile notification pipe into a dependable part of your platform.

About the Author

John Doe - Designer

Router lights can seem confusing, but each colour and blink pattern tells you something useful. Learn what normal looks like and when to restart.

Comments (4)

  1. John Doe - 2 December 2026

    Compulite Written for people who value the details, and want honest guidance they can trust.

  2. John Doe - 29 july 2018

    Compulite An honest, everyday look at the things that make life a little better — with advice you can actually use.

  3. John Doe - 29 july 2018

    Compulite An honest, everyday look at the things that make life a little better — with advice you can actually use.

Leave Comments