---
title: Notification delivery backlog
summary: Diagnose and safely recover when unsent email records accumulate or stop progressing.
version: 1.0.0
type: runbooks
order: 1
badges:
  - content: Runbook
    backgroundColor: orange
    textColor: orange
---

## Trigger / Symptom & Blast Radius

Order emails are delayed, Kafka consumer lag grows on Finance order command topics, messages accumulate in <ResourceLink id="bookworm.{env}.notification.dead-letter-queue" type="channel">`bookworm.{env}.notification.dead-letter-queue`</ResourceLink>, or [[service|notification-api]] logs SMTP or Redis failures. Blast radius is transactional email delivery only; commercial order state in [[service|order-api]] is unaffected.

<Admonition type="danger">
	Never flush BookWorm's shared Redis instance during an outage, and never copy recipient email
	addresses or rendered HTML bodies into incident tickets.
</Admonition>

## Pre-Flight Check

Verify [[service|notification-api]] container status and stream recent logs in `<ENV>`:

```bash
az containerapp show --name <SERVICE_NAME> --resource-group <RESOURCE_GROUP> --query "properties.runningStatus" -o tsv
az containerapp logs show --name <SERVICE_NAME> --resource-group <RESOURCE_GROUP> --tail 150
```

## Quick Recovery Procedure

<Steps>
<Step title="Measure Kafka lag and DLQ depth">

Inspect consumer lag for the `notification` consumer group across <ResourceLink id="bookworm.{env}.finance.place-order" type="channel">`bookworm.{env}.finance.place-order`</ResourceLink>, <ResourceLink id="bookworm.{env}.finance.complete-order" type="channel">`bookworm.{env}.finance.complete-order`</ResourceLink>, and <ResourceLink id="bookworm.{env}.finance.cancel-order" type="channel">`bookworm.{env}.finance.cancel-order`</ResourceLink>, plus depth on <ResourceLink id="bookworm.{env}.notification.dead-letter-queue" type="channel">`bookworm.{env}.notification.dead-letter-queue`</ResourceLink>. Record only lag counts, timestamps, and order/message IDs.

</Step>
<Step title="Diagnose SMTP, resilience, or template faults">

Check [[service|notification-api]] logs for:

**Circuit breaker open / 30s timeouts:** [[service|sendgrid-api]] (or local Mailpit) unreachable or throttling on port `587`.

**SMTP auth failures:** Invalid SMTP username, password, or unverified sender address.

**Redis errors:** Idempotency store unreachable (24-hour deduplication guard).

**Blank recipient email:** Commands with blank/whitespace email addresses are intentionally skipped without error or DLQ entry.

</Step>
<Step title="Restore dependencies and replay DLQ messages">

Fix the failing dependency (SMTP credentials/egress, Redis connectivity, or Kafka broker). Active lag drains automatically. For messages in <ResourceLink id="bookworm.{env}.notification.dead-letter-queue" type="channel">`bookworm.{env}.notification.dead-letter-queue`</ResourceLink>, verify provider delivery logs first to minimize duplicates after ambiguous SMTP timeouts, then replay recoverable messages to their original Finance topic.

</Step>
</Steps>

## Verification

Confirm consumer lag on all three Finance command topics trends to `0`, no new messages enter <ResourceLink id="bookworm.{env}.notification.dead-letter-queue" type="channel">`bookworm.{env}.notification.dead-letter-queue`</ResourceLink>, and container logs show successful SMTP handoffs:

```bash
az containerapp logs show --name <SERVICE_NAME> --resource-group <RESOURCE_GROUP> --tail 50
```

## Rollback / Escalation

- **Rollback:** If a recent [[service|notification-api]] deployment introduced template rendering or SMTP config regressions, roll back to the previous Container App revision in `<RESOURCE_GROUP>`.
- **Escalation:** Escalate SMTP provider/credential issues to [[team|platform-engineering-team]]; escalate template or handler defects to [[team|platform-engineering-team]].

## Related documentation

- [[flow|notification-delivery]] — End-to-end notification delivery flow.
- [[adr|adr-003-notification-smtp-provider-boundary]] — SMTP provider boundary and resilience.
