# Pipeline Backlog Check

Canonical: https://docs.bluehola.com/docs/billing-status/get-health-pipeline
OpenAPI: https://docs.bluehola.com/openapi.yaml

<div class="endpoint"><span class="endpoint-method endpoint-method--get">GET</span><code class="endpoint-path">/health/pipeline</code></div>

Checks whether the sending pipeline is actually moving, by reading the age of the oldest backlog from the database. Meant for external probing.

:::note[Authentication]

This endpoint does not require an API Key.

:::

## Request

Base URL: `https://api.bluehola.com`

## Response

| Status | Description |
| --- | --- |
| `200` | OK — `status` is `ok` and every backlog item is inside its threshold. |
| `503` | A backlog item is past its threshold (`status` is `degraded`, with the same response shape as `200`), or the check could not query the database. |
| `4xx` | Client error |

For the common error envelope and how to handle it, see [Error Codes](../guides/error-codes.md).

### Response fields

For `200` responses and `503` responses caused by a threshold breach, `status`, `checkedAt` and `checks` are required. `checks` requires `outbox`, `accepted` and `sending`; each of those objects requires `ok`, `oldestSeconds`, `pending` and `thresholdSeconds`.

| Field | Type | Meaning |
| --- | --- | --- |
| `status` | string: `ok` or `degraded` | Always `ok` on `200`; `degraded` when any item is past its threshold. |
| `checkedAt` | string (`date-time`) | When the check ran (ISO 8601). |
| `checks` | object | The three backlog checks. |
| `checks.outbox` / `checks.accepted` / `checks.sending` | object | One object per backlog item. |
| `checks.*.ok` | boolean | Whether this item is inside its threshold. |
| `checks.*.oldestSeconds` | number | Age of the oldest item in that state, in seconds; 0 when there is none. |
| `checks.*.pending` | integer | How many items are in that state. |
| `checks.*.thresholdSeconds` | number | The threshold this item is compared against. |

### 200 example

```json
{
  "status": "ok",
  "checkedAt": "2026-11-18T08:00:00.000Z",
  "checks": {
    "outbox": {
      "ok": true,
      "oldestSeconds": 12,
      "pending": 2,
      "thresholdSeconds": 120
    },
    "accepted": {
      "ok": true,
      "oldestSeconds": 30,
      "pending": 4,
      "thresholdSeconds": 300
    },
    "sending": {
      "ok": true,
      "oldestSeconds": 45,
      "pending": 3,
      "thresholdSeconds": 600
    }
  }
}
```

### 503 example (threshold exceeded)

A threshold-related `503` returns the same fields as a `200`. `status` is `degraded`, and `ok` is `false` for each check that exceeded its threshold.

```json
{
  "status": "degraded",
  "checkedAt": "2026-11-18T08:00:00.000Z",
  "checks": {
    "outbox": {
      "ok": false,
      "oldestSeconds": 185,
      "pending": 2,
      "thresholdSeconds": 120
    },
    "accepted": {
      "ok": true,
      "oldestSeconds": 30,
      "pending": 4,
      "thresholdSeconds": 300
    },
    "sending": {
      "ok": true,
      "oldestSeconds": 45,
      "pending": 3,
      "thresholdSeconds": 600
    }
  }
}
```

## Notes

This reads three ages from the database: the oldest unpublished `outbox` event, the oldest message still in `accepted`, and the oldest message still in `sending`. If any of them is past its threshold it returns **503** with each item's details; otherwise **200**.

The defaults are 120s for the oldest unpublished outbox event, 300s for the oldest `accepted` message and 600s for the oldest `sending` message. Adjust them with `PIPELINE_OUTBOX_MAX_SECONDS`, `PIPELINE_ACCEPTED_MAX_SECONDS` and `PIPELINE_SENDING_MAX_SECONDS`.

This is the probe to watch from outside, and to alert on when it returns 503. The readiness check only shows that the API itself can reach PostgreSQL and Redis: when the scheduler is stuck or the message worker stops consuming, `/ready` still returns 200 while customer messages sit in `accepted`. Measuring the backlog in the database is the only way to see that from outside.

It is deliberately **not** folded into `/ready`. The deploy script uses `/ready` to decide whether a new API instance can take traffic; backlog is a worker or scheduler problem, and a new API instance should not be judged unhealthy — and its release failed — because of it.

If the check itself cannot query the database, it returns **503** with `status` `error` and no `checks`. Treat that the same way: the pipeline state is unknown, so alarm on it.

Only messages created in the last 6 hours are counted when looking at `accepted` and `sending` ages; older ones are handled by the send-outcome audit and reservation reconciliation tasks. The result is cached for 10 seconds, so a frequent probe does not query the database every time.
