← All articles

Owlery: a shared outbound mail relay

Design of an internal relay that centralizes transactional email behind per-application keys and a retry queue

Originally published on octa.page ↗

Owlery: shared outbound mail relay

Problem

Several services on the same server called the Resend HTTP API directly, each with its own provider credential. This meant:

  • multiple copies of an equivalent secret, each rotated separately;
  • no per-application restriction on sender addresses;
  • no common delivery log or retry behavior.

Design

Owlery is the single holder of the provider key. It exposes the same request shape as Resend's send endpoint, so migrating a caller means changing the base URL and the key. It is reachable only inside the private network.

Concern Mechanism
Caller identity OneHi application keys, validated through @onehi/client; the key label names the application
Authorization One rule per label: permitted senders (exact address or domain wildcard) and a sending quota. Unknown labels are rejected
Provider failure Message is queued and retried with increasing backoff
Duplicate delivery The message id is reused as the idempotency key on every retry
Persistence SQLite for queue and log, with a JSON mirror of the rules
Operation Web UI with an inbox-style log, usage per key, retry and discard actions, and compact rule editing

Key decisions

Application keys instead of network identity. Most callers run on the same host, so network-level identity cannot distinguish them.

Identity provider outage. The key check in @onehi/client returns null both for an unknown key and when OneHi cannot be reached. Rather than changing the client or adding a persistent key cache, Owlery performs a separate health check on null:

Key check OneHi health Outcome
Known label not consulted Rules applied, message sent
null healthy Rejected, nothing stored
null unreachable Accepted as pending; the key is revalidated before any delivery

Callers treat the pending response as accepted, and Owlery owns the retry.

Calling by service name. All callers, including the monitoring service, use the relay's internal domain instead of loopback. This works across machines on the private network, at the price of making alerts depend on the reverse proxy.

Result

OneHi, Gringotts, Holdings and Osservatore now send through Owlery, each with its own key and sender rule.

Inbound mail was evaluated as a proxy through the relay. One constraint shaped the outcome: MX records bind reception for a whole domain to one service, and the provider's inbound webhook fires for the entire account.