# ESP health check validates connectivity before processing

- **Pattern:** `ab-002461` (`sending-pipeline-infrastructure.esp-integration.esp-health-check`)
- **Severity:** low
- **Lifecycle:** active
- **Last modified:** 2026-04-18
- **Canonical URL:** https://auditbuffet.com/patterns/ab-002461
- **License:** CC-BY-4.0 — attribute to AuditBuffet Pattern Catalog (https://auditbuffet.com/patterns/ab-002461)

## Why it matters

An email worker that starts processing jobs before validating its ESP credentials discovers a misconfiguration only when the first real send fails in production — potentially after dozens of jobs have been dequeued, acknowledged, and logged as in-flight. A rotated API key, a wrong environment variable, or a network policy blocking outbound HTTPS to the ESP creates a failure that only surfaces under load. ISO-25010:2011 reliability.availability requires that faults are detected at startup rather than at runtime, where the blast radius is larger.

## Severity rationale

Low because the failure is discovered quickly (on first job attempt) rather than going undetected, but the absence of a startup check delays diagnosis and allows job state to become inconsistent.

## Remediation

Add a pre-startup health check in `workers/email.worker.ts` that exits the process with a non-zero code if the ESP is unreachable:

```ts
async function startEmailWorker() {
  const healthy = await emailProvider.healthCheck()
  if (!healthy) {
    logger.fatal('ESP health check failed — not starting')
    process.exit(1)
  }
  logger.info('ESP connectivity verified — starting worker')
  const worker = new Worker('email', processEmailJob, { connection })
  worker.on('error', (err) => logger.error(err, 'Worker error'))
}

startEmailWorker().catch((err) => {
  logger.fatal(err, 'Failed to start email worker')
  process.exit(1)
})
```

Verify all configured ESP providers, not just the primary, before the worker accepts its first job.

## Detection

**The detection method for this pattern is part of AuditBuffet Pro.**

The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the [Sending Pipeline & Infrastructure Audit](https://auditbuffet.com/audits/sending-pipeline-infrastructure). The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.

## External references

- iso-25010 reliability.availability

Taxons: operational-readiness

HTML version: https://auditbuffet.com/patterns/ab-002461
