Skip to main content
Aurikle

AI and systems

How to set webhook retry and a dead-letter queue

A webhook on a system you build needs written rules for which results are retried, how the wait grows, how the same event is recognised as a duplicate, and when a used-up event goes to a dead-letter queue instead of being dropped. The API contract names the path, the required fields, and the error codes. The runbook names who answers on this shift. This note says whether an event that failed is sent again.

On this page

Matching serviceCustom software, websites, and applications

Keep retry and the dead-letter queue apart from the contract and the shift

The API contract names the path or the message, the required fields, the authentication, and the error codes. The runbook names who answers in production and where the logs sit. Retry and the dead-letter queue answer a different question: when this event cannot be sent, or the other side has not returned a result that ends it, whether to send it again, how many times, and where it sits afterwards for a person to see. The three can point at the same event number. See How to write an API contract for custom software and How to write an operations runbook for custom software.

Delivery still sits under Custom software, websites, and applications. Secret values are not written into the retry log. See How to rotate secrets and settings for custom software. The cover says whether this webhook is one the company sends or one it receives, and where the rules are kept.

Recognise the same event by source and id

CloudEvents 1.0.2. The specification says it describes event data in a common format so that services, platforms, and systems can interoperate. id is a required, non-empty string and must be unique within the scope of the producer. source is a required, non-empty URI-reference that identifies the context in which the event happened. Producers must ensure that source plus id is unique for each distinct event.

The same page says that if a duplicate event is re-sent, for example because of a network error, it may have the same id. Consumers may assume that events with identical source and id are duplicates. The company uses that pair as the key that marks a repeat. If id or source is empty, the business action is not applied. The event is written to the dead-letter queue as "identity incomplete". A counter or a UUID on the page is only an example. It does not set which form this system must use.

Write which results are retried and which stop

The specification does not list which HTTP results to retry. The company writes two classes: results that are sent again, and results that stop. Sent again covers, for example, no response, or the status codes the company names. Stop covers, for example, the client errors the company names, or an explicit rejection of this payload. Both classes have a date and the person who agreed.

A result in neither class is treated as not yet known. It follows the retry count. It is not recorded as success, and it is not dropped in silence. The company writes the maximum number of attempts. If that maximum is blank, automatic retry is not turned on. An event the other side has already rejected is not sent again just because attempts remain.

The company writes the waits

The specification does not say how long to wait the first time, how the wait grows, or what the longest wait is. If the company lengthens the wait, it writes each wait as its own number and dates it. Without that row, automatic retry stays off. A failed event goes straight to the dead-letter queue, so it is not hammered on a number of seconds that was never written.

The CloudEvents primer 1.0.1 says it is non-normative. Its example is that a CloudEvent intended for a webhook should still be deliverable to a dead-letter queue if the address is unavailable, and that queue should be able to feed later actions the original sender did not imagine. That is a design example. It is not a table of seconds, and it does not name a product.

When the attempts are used up, the event enters the dead-letter queue

A dead-letter row records at least source, id, the number of attempts, the last result, and the time it entered the queue. The business action is not marked complete. The row is not deleted before a person has looked at it.

The person who looks at the dead-letter queue is named on the cover, and the cover points at the place the runbook already uses for the shift. If the name is blank, the queue is only a pile, and the rule is not finished. After it is looked at, the decision is to send once more, to change the other end, or to stop and write why. A blank decision leaves the event on the queue.

A repeat does not apply the business action again

After the receiver applies the business action once for a source and id, it records that pair and the time. If the same pair arrives again, the log says "duplicate". It does not open another order, and it does not change a balance or a status again. The specification allows the receiver to treat the same source and id as a duplicate. The company writes that treatment as required, not optional.

If the first result is still unknown, it is not marked complete. The pair is recorded only when this attempt has a definite result. If two attempts cross, the one written into the completion record first stands. The later one is the duplicate.

The log records the attempt and the result, not a secret

Each attempt records the time, which attempt it was, and the status code or "no response". If the event body contains a secret, the log keeps source and id and not the body. See How to rotate secrets and settings for custom software.

If the operations audit must record who marked an event as no longer to be sent, it uses the fields in the audit note. See How to keep an audit log of actions in custom software. The technical retry log and that audit can point at the same event number. They are not merged into one book.

The webhook is set when the rules, the dead-letter queue, and the owner are written

If either class of result is blank, if the attempt cap is blank, if duplicates are not recognised by source plus id, or if the dead-letter queue has no owner, automatic retry is not turned on. A failed event goes to the dead-letter queue. It is not fired repeatedly in the absence of a rule.

Three checks show it is set: which results retry and which stop are written; the same source and id do not apply the business action twice; and an event that has used its attempts enters the dead-letter queue with someone to take it. A blank item means the event is not marked delivered.

Related notes

Book a consultationCustom software, websites, and applications