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.

ConcernMechanism
Caller identityOneHi application keys, validated through @onehi/client; the key label names the application
AuthorizationOne rule per label: permitted senders (exact address or domain wildcard) and a sending quota. Unknown labels are rejected
Provider failureMessage is queued and retried with increasing backoff
Duplicate deliveryThe message id is reused as the idempotency key on every retry
PersistenceSQLite for queue and log, with a JSON mirror of the rules
OperationWeb 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 checkOneHi healthOutcome
Known labelnot consultedRules applied, message sent
nullhealthyRejected, nothing stored
nullunreachableAccepted 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.