03 Retries Dlq And Failure Events

Retries, DLQ, And Failure Events

Klok integrations must make failures visible and recoverable. The framework patterns provide standard retry and DLQ behavior, but developers and operators must still understand the failure model.

The Principles

  • DLQs are for fatal errors on asynchronous routes.
  • Transient errors are retried.
  • A synchronous service lets its client handle a client error: it answers at once with the error, and the client does what it wants with it.
  • A synchronous retry is decided case by case, for a network issue or similar, with a very short delay and few retries. Anything longer risks that the client gets a timeout instead, and the error is then hidden and really hard to troubleshoot.

How each pattern follows them today is in the framework's principles of error handling.

Transient vs Permanent Failures

A transient failure might succeed later:

  • Network timeout.
  • Temporary target outage.
  • Rate limit.
  • Broker rebalance.

A permanent failure usually needs intervention:

  • Invalid payload.
  • Missing required field.
  • Unknown code value.
  • Authorization misconfiguration.
  • Target rejects the business meaning.

Retry

Offramps commonly use exponential backoff and a bounded number of attempts. Retrying is useful for transient failures, but harmful when the message is poison.

Retry behavior should be observable through logs, traces, and metrics. Repeated retries should not hide a failing target system.

Dead Letter Queue

After retries are exhausted, the message moves to a DLQ, the topic <topic>_DLQ. The DLQ protects the main flow from being blocked by one bad message. It is created together with its topic, never on the first failure, and a service checks at startup that it can write every DLQ it may need (Topics On The Klok Broker).

DLQ handling should answer:

  • Which message failed?
  • Which route failed?
  • What error category was recorded?
  • Is the payload invalid or was the target unavailable?
  • Can the message be replayed safely?
  • Is manual correction required?
  • Will replay cause duplicates?

Failure Events

Failure events are standardized CloudEvents that operations teams can subscribe to. They are better than log scraping for business-critical failure notification.

A failure event should include enough metadata to route the incident without leaking secrets or full sensitive payloads.

DLQ Review Checklist

  • [ ] Correlation ID is present.
  • [ ] Route ID is present.
  • [ ] Topic and data model are known.
  • [ ] Error category is clear.
  • [ ] Owner is known.
  • [ ] Replay safety is understood.
  • [ ] Fix is documented.
  • [ ] Repeated failures create a follow-up task.