> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bbrands.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Delivery pipeline

> How a send travels from the database to the provider: the QStash notification topic, the lanes per channel, retries, failed messages, scheduled sends and the jobs that keep it moving.

## What it is for

Once a decision creates a send, the send has to leave without being lost or sent twice, at a pace each provider
accepts. This page explains that path. It replaces the old "Architecture" page of the OneSignal era, which now
redirects here.

![Diagram: the notification queue spreads the sends over six lanes; Email goes to Resend; In-app goes to the Horizon inbox; Push, SMS and Live Activity go to OneSignal; WhatsApp is reserved and has no provider.](https://mintcdn.com/bbrands/_njGa-AUVffoWNDA/images/notification-user-manual/channel-lanes.svg?fit=max\&auto=format\&n=_njGa-AUVffoWNDA\&q=85\&s=bcca131ffe4af22db7641224c5a3ffae)

Each send enters the notification queue and leaves on its channel's lane towards its provider.

## The path of a send

1. **Stored.** The send is written in the database with status **Queued**, or **Scheduled** if it must wait for
   quiet hours or a delay.
2. **Ledger first.** Before publishing, Horizon writes a queue record (`queue_event`) in status `received`. If the
   publish fails, that record lets a job publish it again later; the send is never stuck without trace.
3. **Published.** A short message (`notification`, `channel`, `correlation`) goes to the QStash topic
   `notification`. The database row is the source of truth; the message only points to it.
4. **Lane.** The channel picks the lane, which controls how many sends of that channel leave at once and how fast.
5. **Consumer.** QStash calls Horizon's notification consumer. It loads the send, marks it **Sending** and hands it
   to the channel's adapter.
6. **Provider.** The adapter calls Resend or OneSignal, or writes the in-app item. The send becomes **Sent** (or
   **Skipped** if, for example, no device is subscribed).
7. **Delivery events.** The provider reports back by webhook and the send moves to **Delivered**, **Opened**,
   **Clicked**, **Bounced**, **Marked as spam** or **Failed** (see
   [Providers and webhooks](https://docs.bbrands.io/enterprise/notifications/reference/providers.md)).
8. **Told to subscribers.** Each status a send really reaches (**Delivered**, **Opened**, **Clicked**,
   **Bounced**, **Marked as spam**, **Failed**, **Skipped**) is published once as an outbound webhook event, and so
   is every channel the engine decided not to send. An integration that sent through the API gets its own
   `idempotency_key` back and can limit its webhook to its gateway (see
   [Event catalogue](https://docs.bbrands.io/webhooks/event-catalogue.md#notification)).

## Lanes

There is one queue (`notification`) and one lane per channel. A slow or failing provider only holds its own lane.

| Lane | Channel | Sends at once | Pace |
| - | - | - | - |
| `notification-email` | Email | 3 | 2 per second |
| `notification-push` | Push | 4 | No limit |
| `notification-in-app` | In-app | 2 | No limit |
| `notification-sms` | SMS | 2 | No limit |
| `notification-live-activity` | Live Activity | 2 | No limit |
| `notification-whatsapp` | WhatsApp (reserved) | 1 | No limit |
| `notification` | Fallback for messages without a channel | 1 | No limit |

The email pace follows Resend's limit. Pausing a lane in [**Queues**](https://docs.bbrands.io/enterprise/notifications/operation/queues.md) holds its sends without changing any decision;
they leave in order when the lane is resumed.

## Retries and failed messages

| Situation | What happens |
| - | - |
| Temporary error (provider down, rate limit, network) | The consumer retries up to 5 times, waiting longer each time (5 s, 10 s, 20 s…) |
| Retries exhausted | The send becomes **Failed**, its fallback channel runs if it has one, and the message is kept as a **failed message** |
| Permanent error (the provider rejects the content or the address) | The send becomes **Failed** at once, without retries |
| Nothing to deliver to (no device, provider not configured) | The send becomes **Skipped** |
| Malformed message | It is set aside as a failed message at once, without retries |

Failed messages are listed in [**Queues › Failed messages**](https://docs.bbrands.io/enterprise/notifications/operation/failed-messages.md), where an operator replays them after fixing the cause
(see [Operations runbook](https://docs.bbrands.io/enterprise/notifications/reference/operations-runbook.md)).

## Manual retry and resend

**Retry** (`POST /{id}/retry`) puts a **Failed** send back in the queue, and replaying a failed message whose send
ended **Failed** does the same. **Resend** (`POST /{id}/resend`) creates a new send linked to the original. Before
writing anything, both run the check of the release job without the time to live: the event and channel are still
on, the address is not suppressed and the customer still accepts the send, honouring the event's bypasses. Quiet
hours and the frequency cap do not apply to a one-off manual send. If the check refuses, the API answers
`409 notification-not-eligible` with the decision reason and nothing is written. There is no override: lift the
suppression or change the preference first.

## No send goes out twice

| Protection | How |
| - | - |
| Same occurrence | The send id is derived from the occurrence, the channel and the recipient |
| Same integration request | `external_id` is unique per gateway |
| Same queue message | The queue ledger is keyed by the send id, so a second publish is ignored |
| Same provider call | The send id travels as the provider's idempotency key (Resend and OneSignal) |
| Same webhook event | Delivery events are unique per provider and provider event id |
| Status | A status only moves forward: a late or repeated write changes nothing |

## The jobs that keep it moving

| Job | Every | What it does |
| - | - | - |
| Release scheduled sends | Minute | Moves due **Scheduled** sends to **Queued** and publishes them. Before that it checks again that the event and channel are on, the address is not suppressed, the customer still accepts it and the time to live has not passed; otherwise the send is **Cancelled** or **Expired** |
| Requeue stalled events | 10 minutes | Publishes again queue records left open for more than 15 minutes (up to 50 per run) |
| Metrics rollup | 10 minutes, and a daily pass | Recomputes the dashboard figures |
| Alert evaluation | 5 minutes | Checks the alert rules and posts to Slack and Better Stack |
| Email HTML purge | Daily, 04:30 | Deletes the rendered HTML of emails older than 180 days; subject and data stay |
| Retention purge | Daily, 04:45 | Deletes inbox items after 180 days (purged at 365) and sends, events, occurrences and decisions after 13 months |

## Technical detail

| Aspect | Detail |
| - | - |
| Transport | `backend/horizon-api/lib/queue/transport/` (`QUEUE_PROVIDER`: `qstash` by default; `inline` for local work) |
| Topic and event types | `backend/horizon-api/lib/queue/notification/notification-queue-topics.ts` |
| Enqueue (outbox) | `backend/horizon-api/lib/notification/core/notification-enqueue.ts` |
| Consumer | `POST /api/queue/consumers/notification` → `notification-unified.handler.ts` → `core/notification-delivery.service.ts` |
| Lanes | `backend/horizon-api/lib/queue/lane/queue-lane.defaults.ts` and `queue-lane-map.ts` |
| Retries | `backend/horizon-api/lib/queue/common/queue-consumer-wrapper.ts` (5 attempts) |
| Status transitions | `backend/horizon-api/lib/notification/core/notification-status.ts` (`NOTIFICATION_TRANSITIONS`) |
| Jobs | `backend/horizon-api/app/api/v3/cron/notification/**` and `cron/queue/event/reconcile`; schedules in `backend/horizon-api/vercel.json` |
| Scheduler | `backend/horizon-api/lib/notification/core/notification-scheduler.service.ts` |
| Manual retry and resend | `backend/horizon-api/lib/notification/resend/notification-resend.service.ts`; the check is `recheckManualSend` in `backend/horizon-api/lib/notification/eligibility/eligibility-pipeline.ts` |

## Related and history

* [Architecture](https://docs.bbrands.io/enterprise/notifications/reference/architecture.md)
* [Channels overview](https://docs.bbrands.io/enterprise/notifications/channels/overview.md)
* [Operations runbook](https://docs.bbrands.io/enterprise/notifications/reference/operations-runbook.md)

| Date | Change |
| - | - |
| 2026-11-11 | First version, rewritten from the old "Architecture" page, which now redirects here |
| 2026-11-12 | Manual retry and resend check the event, the channel, suppressions and opt-outs again (issue #2203) |
| 2026-11-23 | Every delivery state and every skipped channel is published as an outbound webhook event (contactability-events REQ-10) |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.