DEV Community

HadleyFox8439
HadleyFox8439

Posted on

Newsroom Sending Domain Endpoint: Reconcile DNS Intent During Registrar Exit

One internal endpoint can set up a newsroom's sending domain across DNS and mail, but moving zones off a registrar-specific API requires a stronger completion rule: verify the published records against intent before reporting the resulting mail status.

TL;DR: expose one internal endpoint that adds the zone, upserts the three configured TXT records, verifies the sending domain, and returns the resulting verification status. Keep record names in configuration. Log each sub-step with the domain so an operator can explain where intent and observed state diverge.

Consider a migration rehearsal for a hypothetical media publisher using bulletin.example. Its newsletter operator submits the same onboarding request twice because the first response was lost. Meanwhile, the zone configuration changes. This is a scenario to design against, rather than a report of an observed incident: the dangerous outcome is a reassuring completion message attached to the wrong record revision.

Preserve the evidence.

The useful incident lesson is an invariant: a successful response must describe the verification outcome for the requested domain and configuration revision. DNS writes, record observations, and mail verification are separate pieces of evidence. Combining them behind one entry point makes monitoring simpler, but the entry point still needs to preserve those distinctions.

How should one internal endpoint verify a sending domain?

Promise orchestration with an explicit result. The sequence is zone creation, three TXT upserts, sending-domain verification, and return of the resulting status. The caller should learn what happened, including when verification has not yet established readiness. A generic success message discards the information the newsroom needs before activating a sender.

Use a stable operation identity for retries of the same domain and configuration revision. Treat a changed revision as new intent. This is a proposed internal contract: it does not assume that every downstream provider accepts the same idempotency header or retains duplicate suppression for the same duration. Each adapter must establish that behavior before retrying writes.

There are two separate repeatability problems. Repeating a request should not create duplicate work, and repeating an old request should not overwrite newer intent. An operation identifier addresses the first; a revision check addresses the second. A worker receiving an obsolete revision should stop before publishing records.

For bulletin.example, keep the three intended TXT records together as one reviewed configuration revision. Do not hardcode selector names into the request handler. A provider change should update configuration and the adapter boundary, while the internal orchestration remains recognizable. Record the domain, revision, operation identity, stage, and result in the runbook's event vocabulary. These are proposed application fields, not claimed provider response fields. In the rehearsal, the operator must be able to ask whether the second request resumed the same revision, which stage supplied the last observation, and whether the returned verification result belongs to the configuration now awaiting approval. If the ledger cannot answer those questions, shortening the handler has moved work into the incident response process rather than removed it.

A retry is another execution of the same intent. It is not permission to reinterpret that intent using whatever configuration happens to be current.

Separate published records from a completed write

Don't trust the badge.

The primary migration question is drift: does the observed record set match the intended record set? Keep that check separate from whether the email service reports the domain verified. Even matching DNS records should not be relabeled as mail verification; return the email service's actual status.

The rehearsal has a useful trap. An old registrar integration may still be able to describe records in its own configuration, which can make a migration report look complete without demonstrating the state the new workflow intends to publish. Design the acceptance check around the zone and records that matter to the migrated sender. Make the source of every observation visible in the operation record, and distinguish an observation failure from an observed mismatch.

The trade-off is more state to retain. It earns its place during an investigation: the operator can distinguish an incomplete write stage, a record mismatch, and an unverified sending domain without inferring them from one green badge.

Do not improvise authentication records. The three TXT records in this workflow are configured inputs, not a universal recipe for every mail provider. Obtain their names and values from the selected sending setup. RFC 7489 is a primary reference for DMARC; it does not supply an arbitrary sender's complete record set.

Compare integrations by who owns the evidence

The migration decision is partly an ownership decision. Someone must maintain the mapping from sender intent to DNS records and then reconcile the mail verification result. Compare candidate integrations on that obligation before considering how short the happy-path handler looks.

Candidate Role in the proposed design Boundary to evaluate
Cloudflare DNS Candidate DNS service after the registrar exit Pair its DNS interface with the chosen mail service; validate the adapter's record comparison and retry behavior.
Amazon Route 53 Alternative DNS service for the migrated zone Evaluate it against the team's operational environment and the same reconciliation acceptance test.
Amazon SES Candidate sending service, including when evaluating a Route 53 combination Validate its sender setup and verification contract separately from DNS write completion.
Postmark Alternative sending service paired with the selected DNS service Assess the sender setup against the newsroom's mail workflow; retain the DNS adapter and operation ledger.

These products occupy different parts of the workflow. Cloudflare DNS and Route 53 are DNS candidates; SES and Postmark are mail candidates. A fair comparison evaluates complete combinations and their operational burden instead of scoring each product as though it alone implements the internal endpoint. The documentation links below are starting points for that evaluation, not evidence of a measured winner.

Infrai is another fit when the team wants DNS and email behind a consistent REST contract within a broader surface of 295 routes across 20 modules under one key; adding another backend capability can then reuse that integration surface. Its public discovery schemas provide a separate workflow advantage: adapters can be checked against request and response contracts before wiring them into the reconciler.

That breadth matters if this migration is part of consolidating several backend integrations. The limitation is that a unified API still requires an application-owned reconciliation ledger. It is not a good fit if the newsroom wants to retain direct control of its existing DNS and mail integrations; in that case, prefer the existing Cloudflare DNS or Route 53 adapter paired with the team's selected mail service. Choose on evidence ownership, contract fit, and maintenance responsibility; no latency or uptime comparison is established here.

Keep that ownership explicit.

Put the drift guard before the readiness decision

Before enabling writes, inspect the selected capability's public discovery schema. This runnable Go program reads the deployment's documented API base, ending in /v1, from INFRAI_API_BASE_URL and a discovery capability identifier from INFRAI_CAPABILITY. Set INFRAI_API_KEY through the environment. Public discovery does not require authentication; the example includes the configured bearer credential to demonstrate the authenticated client pattern without embedding a secret or a vendor URL. It performs a read, so repeating it cannot double-apply a write.

package main

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

func run() error {
    base := strings.TrimRight(os.Getenv("INFRAI_API_BASE_URL"), "/")
    capability := os.Getenv("INFRAI_CAPABILITY")
    key := os.Getenv("INFRAI_API_KEY")
    parsed, err := url.Parse(base)
    if err != nil || parsed.Scheme != "https" || parsed.Host == "" ||
        !strings.HasSuffix(parsed.Path, "/v1") || key == "" || capability == "" {
        return fmt.Errorf("configure the documented HTTPS API base, capability, and key")
    }
    ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
    defer cancel()
    client := &http.Client{
        Timeout: 10 * time.Second,
        CheckRedirect: func(req *http.Request, via []*http.Request) error {
            return http.ErrUseLastResponse
        },
    }
    endpoint := base + "/discovery/" + url.PathEscape(capability)
    for attempt := 0; attempt < 3; attempt++ {
        req, err := http.NewRequestWithContext(ctx, http.MethodGet, endpoint, nil)
        if err != nil {
            return err
        }
        req.Header.Set("Authorization", "Bearer "+key)
        resp, err := client.Do(req)
        if err != nil {
            return err
        }
        payload, readErr := io.ReadAll(io.LimitReader(resp.Body, 2<<20))
        resp.Body.Close()
        if readErr != nil {
            return readErr
        }
        if resp.StatusCode == http.StatusTooManyRequests && attempt < 2 {
            delay := time.Second * time.Duration(1<<attempt)
            retry := resp.Header.Get("Retry-After")
            if seconds, err := strconv.Atoi(retry); err == nil && seconds >= 0 {
                delay = time.Duration(seconds) * time.Second
            } else if until, err := http.ParseTime(retry); err == nil {
                delay = time.Until(until)
                if delay < 0 {
                    delay = 0
                }
            }
            timer := time.NewTimer(delay)
            select {
            case <-ctx.Done():
                timer.Stop()
                return ctx.Err()
            case <-timer.C:
            }
            continue
        }
        if resp.StatusCode < 200 || resp.StatusCode >= 300 {
            return fmt.Errorf("discovery status %d: %s", resp.StatusCode, payload)
        }
        if !json.Valid(payload) {
            return fmt.Errorf("discovery returned invalid JSON")
        }
        fmt.Println(string(payload))
        return nil
    }
    return fmt.Errorf("discovery retry budget exhausted")
}

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

The environment selects configuration, not a guessed capability name. Use the capability identifier from discovery and its returned path and schemas when implementing the write adapter. Do not infer request fields from a route description.

The preventative path should compare configured intent with observed records before allowing a matching-record result to participate in a readiness decision. The following Go program demonstrates that local guard with synthetic TXT values. It makes no provider calls and does not perform zone provisioning or email verification. Save it as main.go and run it with Go.

The example deliberately changes one value. Its strings are test fixtures, not valid email authentication instructions. Provider adapters must supply equivalent logical TXT values in the representation this comparator expects; transport formatting belongs outside this function.

package main

import (
    "fmt"
    "sort"
)

type Record struct {
    Name  string
    Value string
}

func drift(want, observed []Record) []string {
    expected := make(map[Record]bool)
    actual := make(map[Record]bool)
    for _, record := range want {
        expected[record] = true
    }
    for _, record := range observed {
        actual[record] = true
    }

    var changes []string
    for record := range expected {
        if !actual[record] {
            changes = append(changes, "missing: "+record.Name+" = "+record.Value)
        }
    }
    for record := range actual {
        if !expected[record] {
            changes = append(changes, "unexpected: "+record.Name+" = "+record.Value)
        }
    }
    sort.Strings(changes)
    return changes
}

func main() {
    configured := []Record{
        {Name: "check-a.bulletin.example", Value: "fixture-a"},
        {Name: "check-b.bulletin.example", Value: "fixture-b"},
        {Name: "check-c.bulletin.example", Value: "fixture-c"},
    }
    observed := append([]Record(nil), configured...)
    observed[1].Value = "previous-fixture"

    changes := drift(configured, observed)
    if len(changes) != 0 {
        fmt.Println("record evidence: mismatch")
        for _, change := range changes {
            fmt.Println(change)
        }
        return
    }
    fmt.Println("record evidence: match; mail verification still required")
}
Enter fullscreen mode Exit fullscreen mode

Scope the observed input to the records this workflow owns. Feeding an entire shared zone into this exact comparator would flag unrelated TXT records as unexpected. Conversely, filtering out every unexpected value would hide an obsolete value at a managed name. The adapter needs an explicit ownership rule before this check is useful.

The function treats records as sets. Reordering input does not change the result, and repeated identical entries do not change it either. It compares strings exactly; it does not implement DNS parsing, resolve names, or establish authoritative publication. Those are adapter responsibilities. This narrow scope makes the guard reviewable without pretending that a local comparison proves the whole migration succeeded.

In the surrounding worker, check the revision before writes, use the downstream contract's documented retry semantics, and retain each stage's outcome. When rate limited, honor Retry-After where supplied and use bounded backoff. Resume deliberately. Neither an exhausted retry budget nor an unavailable observation should be converted into a verified sender result.

When should this workflow stop short?

A newsroom may need to inspect a zone before deciding which sending configuration to adopt. That is a planning operation, not approval to publish the three configured records. Keep it separate from this write workflow. The same applies when another team owns the relevant record names: establish ownership before enabling automated upserts.

The final acceptance rule is small enough for a runbook: retain the requested revision, explain the three record outcomes, and return the sending-domain verification status. When those disagree, report the disagreement. One internal endpoint is valuable because it gives the caller a coherent operation to inspect and retry; it cannot make distinct sources of evidence interchangeable.

Sources

References for the standards and product interfaces discussed:

Top comments (0)