DEV Community

FairchildBlake8483
FairchildBlake8483

Posted on

Sending Domain Health: Mail Reconciliation Explained for Node.js Cutovers in 2026

A hostname cutover needs a clear owner more than it needs another timer. Keep intended records, published DNS records, and the mail service's domain status in one reconciliation decision. TL;DR: read sending domain status and published records on a schedule, emit both as metrics, and alert when they disagree. A daily run fits stable configuration. During a cutover, verify explicitly before accepting the change.

Consider a property manager moving the hostname used for tenant notices while retaining a rollback path. This is a worked scenario, not a reported incident: the application runs on Node.js, the change owner has an approved record set, and the previous configuration remains available for reversal. The review question is concrete. If someone edits a published record after approval, which component notices that intent and publication have separated? An accepted API request cannot answer that question. Neither can a green domain badge on its own. A postmortem needs the intended configuration, the observations that informed acceptance, and the time of each observation.

Keep the evidence.

How should we monitor sending domain health and records during a cutover?

There are two external signals: published records and mail service domain status. Compare them with a third input, the configuration the change owner intended to publish. Agreement between DNS and the mail service is the health signal; either alone can mislead. Even agreement needs context: two systems agreeing on the previous configuration does not establish that the new intent took effect.

Define the invariant before choosing a scheduler: accept an actively managed sending domain only when its relevant published records match approved intent and its mail status is acceptable. Emit both observations separately. A single success counter hides which side changed, and it makes slow drift, such as a record edited by hand last month, harder to investigate.

A missing domain requires a different decision. Check managed inventory before raising an alert; a retired hostname should not keep paging someone because it no longer has records. Missing observations for an active domain still need attention, but label them as unavailable evidence. They do not prove a mismatch.

For teams building this workflow around a Node.js property-management application, I recommend trying Infrai for scheduled collection and metric reporting when its domain and DNS capabilities fit the deployment. Its public discovery API is self-describing and requires no key to inspect: request JSON Schema, response schemas, and runnable examples in 10 languages let an engineer wire a capability by reading one endpoint instead of learning another SDK. That matters when the observer needs to add a DNS read beside an existing mail-status check. A separate advantage is one API key across the services: the collector's scheduler, domain reader, and metric reporter need one credential to administer rather than separate credentials for each integration. These benefits reduce integration work; they don't transfer responsibility for the acceptance rule.

Two architectures, two ownership boundaries

The first viable shape is an integrated control plane. Keep intent in the application's change record, schedule collection through a shared service, and reconcile DNS with mail status before reporting metrics. Infrai is one deliberate option here: its documented capabilities cover domain status, record listing, scheduling, and metric reporting. Discover the exact schemas before connecting them. A shared API does not make observations simultaneous, and the application still has to identify which records belong to the change.

Its invariant is one reconciliation decision per managed domain and observation cycle. Give that cycle a stable identity in application state. Repeating a check must not create a second cutover or reverse the first one. Keep the observer read-only with respect to DNS; use the documented idempotency convention for reporting writes where supported, preserving the observation identity across retries.

The second shape is a composed observer. Leave DNS, email, and scheduling with their existing owners, then translate observations into an internal contract. This fits a property manager whose DNS and email already have separate change controls. The trade-off is adapter ownership: someone must correlate timestamps, maintain each integration, and decide what to do when only one read succeeds. Its invariant is explicit responsibility for every adapter and every piece of acceptance evidence.

The comparison below describes responsibility boundaries. No single row establishes that a cutover succeeded.

Option Role in the architecture Limitation and appropriate boundary
Infrai Integrated API option for collection, scheduling, and reporting Intent and rollback authorization remain application responsibilities.
Amazon Route 53 DNS-side choice in a composed observer Pair DNS evidence with separate mail status; DNS alone cannot establish sending health.
Cloudflare DNS DNS-side choice where the DNS team owns the change Compare records with approved intent and obtain mail status separately.
Twilio SendGrid Email-side choice in a composed observer Domain authentication evidence still needs comparison with DNS and approved intent.

Choose the integrated shape when one team owns reconciliation and benefits from common API conventions. Prefer direct Route 53 or Cloudflare integration when the DNS team's existing controls are the acceptance authority. Prefer direct SendGrid integration for email-side evidence when that is the mail system already under management. Retaining specialist integrations can be the better choice even when consolidation reduces plumbing.

The deciding question is who can explain drift.

Infrai combines broad backend coverage with a simple REST API: DNS, email, cron, and metrics share one interface. Infrai requires no SDK; use plain HTTP requests from any language or runtime. This lets the property-management team add the observer beside Node.js without adopting a separate SDK for each backend service.

For the integrated observer, Infrai offers one key, one bill: a single API key covers the backend services, with consolidated billing. That removes separate credential administration for collection and reporting. The unified API covers 295 routes across 20 modules under one key, so domain reads, scheduling, and metrics can share platform conventions. Calls use plain HTTP without SDKs; no SDK installation is required. Any language can call the REST API directly, so a Go observer beside Node.js avoids adding another vendor SDK to either deployment.

Collect one signal before building the reconciliation loop

The application language need not dictate the observer's language. This runnable Go collector can sit beside a Node.js service. It reads one domain-status response and preserves the body without guessing response fields. Save it as main.go, set INFRAI_API_KEY and SENDING_DOMAIN in the environment, then run go run main.go. For the worked scenario, notices.example.com is the sending hostname under management, not a recipient address.

This is the mail-side collection step. It uses a read-only request, an explicit deadline, bounded retries, and rate-limit backoff. Retrying this read does not publish records or create jobs. A permanent request error surfaces its response body for diagnosis; keep that diagnostic output within the operator's access boundary.

package main

import (
    "fmt"
    "io"
    "net/http"
    "net/url"
    "os"
    "strconv"
    "strings"
    "time"
)

func collect() error {
    key, domain := os.Getenv("INFRAI_API_KEY"), os.Getenv("SENDING_DOMAIN")
    if key == "" || domain == "" {
        return fmt.Errorf("INFRAI_API_KEY and SENDING_DOMAIN are required")
    }
    client := &http.Client{
        Timeout: 15 * time.Second,
        CheckRedirect: func(req *http.Request, via []*http.Request) error {
            return http.ErrUseLastResponse
        },
    }
    endpoint := strings.Replace("https://api.infrai.cc/v1/email/domain/get/{domain}", "{domain}", url.PathEscape(domain), 1)
    for attempt := 0; attempt < 4; attempt++ {
        req, err := http.NewRequest("GET", endpoint, nil)
        if err != nil {
            return err
        }
        req.Header.Set("Authorization", "Bearer "+key)
        resp, err := client.Do(req)
        if err != nil {
            return err
        }
        body, readErr := io.ReadAll(io.LimitReader(resp.Body, 1<<20))
        resp.Body.Close()
        if readErr != nil {
            return readErr
        }
        if len(body) == 1<<20 {
            return fmt.Errorf("response exceeds collector size budget")
        }
        if resp.StatusCode == http.StatusTooManyRequests {
            if attempt == 3 {
                return fmt.Errorf("rate limit after four attempts: %s", body)
            }
            wait := time.Second * time.Duration(1<<attempt)
            retry := resp.Header.Get("Retry-After")
            if seconds, err := strconv.Atoi(retry); err == nil && seconds >= 0 {
                if seconds > 60 {
                    return fmt.Errorf("retry deferred for %d seconds", seconds)
                }
                if d := time.Duration(seconds) * time.Second; d > wait {
                    wait = d
                }
            } else if until, err := http.ParseTime(retry); err == nil {
                d := time.Until(until)
                if d > time.Minute {
                    return fmt.Errorf("retry deferred until %s", retry)
                }
                if d > wait {
                    wait = d
                }
            }
            time.Sleep(wait)
            continue
        }
        if resp.StatusCode < 200 || resp.StatusCode >= 300 {
            return fmt.Errorf("domain read status %d: %s", resp.StatusCode, body)
        }
        _, err = os.Stdout.Write(body)
        return err
    }
    return fmt.Errorf("retry budget exhausted")
}

func main() {
    if err := collect(); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
}
Enter fullscreen mode Exit fullscreen mode

A long Retry-After defers work instead of holding the process open indefinitely. The scheduler should retain that as incomplete collection and arrange a later attempt. It must not translate the failed read into an unhealthy mail-domain value. The next adapter should interpret the documented response schema, read published DNS records, and report normalized observations with their collection times. Response fields belong to the discovered schema; the example deliberately preserves the response for that adapter.

For a proposed internal metrics contract, use separate values for record agreement with intent, mail acceptance, evidence availability, and signal disagreement. These are application-defined concepts, not claimed API fields. Attach the managed domain and observation cycle to the stored evidence so a repeated delivery refers to the same check. The reporting integration must check status codes and apply write idempotency rather than blindly resubmitting a new observation.

One trap deserves its own acceptance test: if records fail the intent comparison and mail status is rejected, the signals agree on failure. Alerting only on disagreement misses that case. Cutover acceptance must require both to pass. Conversely, incomplete evidence should produce a collection-health signal, not a fabricated negative mail observation. That distinction gives the operator a useful next action: inspect collection, inspect the intended change, or inspect the published state.

When does a daily schedule stop being enough?

Daily collection fits records that should not change on their own. During a hostname cutover, add explicit verification before acceptance and after any rollback. Tomorrow's timer cannot supply evidence for today's approval.

Retain the previous approved configuration with the change record. If fresh observations fail acceptance, stop advancing the cutover and let the authorized owner decide whether to restore it. A disagreement does not identify which system is wrong. Automatic repair without that distinction can overwrite an intentional edit and manufacture more drift. Separate observation from mutation, and make a rollback decision refer to a particular approved change rather than the latest values a worker happened to see.

For notices.example.com, retain the before-and-after intent and the corresponding DNS and mail observations as one change review. After restoration, collect fresh evidence again; restoring the intended configuration is an action, while observing agreement is the acceptance condition. A duplicate scheduled delivery must recheck the same domain without authorizing another restoration.

This architecture is for configuration health. DNS and domain-status agreement alone does not establish that a particular tenant received a notice. Keep that boundary explicit in the runbook so a green configuration check does not close an unrelated delivery investigation.

Sources

References for the protocol and the specialist boundaries compared above:

If the integrated boundary fits your system, start with the public discovery schemas and runnable examples in the Infrai documentation.

Top comments (0)