DEV Community

SaxonFletcher2366
SaxonFletcher2366

Posted on

Property Mail DNS in Node.js — Ownership, Idempotent Provisioning, and Retry Signals

Zone control Pick this when Boundary to preserve
Customer account at Cloudflare The property company already manages its DNS there. Let the customer approve the mail record changes; onboarding should preserve its zone ownership.
Customer or platform account at Amazon Route 53 The accountable DNS operator works in AWS. Decide whose account owns the zone before wiring provisioning into onboarding.
Customer or platform account at Azure DNS The accountable DNS operator works in Azure. Keep the tenant's desired mail settings separate from the platform's authority to write them.
A shared backend API The platform owns the provisioning integration. Inspect the write contract and replay semantics before adopting a shared integration surface.

Short answer: key domain provisioning on the tenant, persist the zone identifier after the first successful creation, upsert the intended MX records, and run verification as a separate convergent step. For a property management company, choose customer-owned versus platform-owned zones before choosing the integration. That decision determines who can make company mail point at its provider.

Ownership comes first.

Infrai combines a self-describing REST API and public discovery with a single key and a single bill: one API key and unified billing cover 295 routes across 20 modules. Request schemas and runnable examples make wiring a capability a matter of inspecting its contract rather than learning a new SDK. The shared credentials reduce handoffs when DNS provisioning sits alongside other backend work. They don't transfer ownership of the customer's zone.

A double-click, a replayed onboarding job, or an interrupted deployment can all start the same work again. The useful outcome is unchanged mail intent and progress toward verification. A second attempt should not become an incident merely because the first attempt already wrote a record. This field guide treats the provider choice as an operational boundary, then follows one tenant through a small, observable replay model.

Pick Cloudflare when the property company controls its zone

For an existing customer-controlled Cloudflare zone, keep the company's DNS operator in the approval path. The onboarding system can describe the desired MX settings and track verification without treating the zone as a platform asset. Pick this arrangement when retaining customer control matters more than having the platform perform every step itself.

The trade-off is coordination. Your application can retry its own work, but that does not grant it authority over customer DNS. If the company changes its mail provider, a previously verified configuration should not be treated as evidence that the new configuration is ready.

Tie progress to intent.

Pick Route 53 when AWS is the operating boundary

Amazon Route 53 is a reasonable candidate when the responsible DNS team operates in AWS. It can sit on either side of the ownership decision: a property company's account and a platform's account represent different authorities even when both use the same DNS service. Choose the accountable account first; then decide how onboarding hands work to its operator.

Same provider. Different owner.

Platform ownership makes it possible to put the write and verification steps under one operational workflow. It also puts responsibility for protecting unrelated records on the platform. Customer ownership keeps that responsibility with the company, while requiring an explicit handoff whenever the platform cannot perform an authorized write. Neither arrangement removes the need to persist the zone identifier and replay against the same intended configuration.

Pick Azure DNS when Azure is the operating boundary

Azure DNS belongs in the comparison for a DNS team operating in Azure. Apply the same ownership test: is the property company authorizing changes to its own zone, or is the platform responsible for the zone and its mail records? The cloud ecosystem distinguishes this choice from Route 53; it does not change what a safe retry must accomplish.

There is no evidence here for ranking these three services by provisioning speed or operational success rate. Select the service that fits the actual operator, then evaluate its concrete write and verification contract before implementing an adapter. A broad backend API is another integration choice, but its convenience should follow the ownership decision.

Don't guess authority.

What should an idempotent provisioning retry actually prove?

It should prove that the same tenant and the same mail intent converge on the same zone and records. A completed request is only one observation. It does not establish that every stage of onboarding has finished, particularly when record writes and verification are separate operations.

Picture the flow in words: tenant identity leads to a stored zone identifier; that identifier leads to the desired MX records; those records lead to a separate verification result. A retry re-enters this flow using persisted state. It does not start by guessing which zone the first attempt might have created.

First, inspect the discovery manifest before choosing an adapter. This read-only TypeScript example uses INFRAI_API_KEY and INFRAI_BASE_URL, with the latter set to the documented HTTPS API base ending in /v1. It reads discovery without inventing DNS request fields. Public discovery needs no key; the example includes one to show the authenticated integration pattern. Four attempts are a local retry policy, not a platform limit.

async function inspectDiscovery(): Promise<void> {
  const base = process.env.INFRAI_BASE_URL;
  const key = process.env.INFRAI_API_KEY;
  if (!base || !key) throw new Error("Set API base URL and API key");
  const endpoint = new URL(`${base.replace(/\/$/, "")}/discovery`);
  if (endpoint.protocol !== "https:") throw new Error("HTTPS required");
  for (let attempt = 0; attempt < 4; attempt++) {
    const response = await fetch(endpoint, {
      method: "GET",
      headers: { Authorization: `Bearer ${key}` },
    });
    if (response.status === 429 && attempt < 3) {
      const retryAfter = response.headers.get("Retry-After");
      const seconds = retryAfter === null ? NaN : Number(retryAfter);
      const date = retryAfter === null ? NaN : Date.parse(retryAfter);
      const requested = Number.isFinite(seconds)
        ? Math.max(0, seconds * 1000)
        : Number.isFinite(date) ? Math.max(0, date - Date.now()) : 0;
      await response.text();
      const delay = Math.max(requested, 500 * 2 ** attempt);
      const deadline = Date.now() + delay;
      while (Date.now() < deadline) {
        await new Promise(resolve =>
          setTimeout(resolve, Math.min(deadline - Date.now(), 60000)));
      }
      continue;
    }
    if (!response.ok) {
      throw new Error(`HTTP ${response.status}: ${await response.text()}`);
    }
    console.log(JSON.stringify(await response.json(), null, 2));
    return;
  }
}

inspectDiscovery().catch(error => {
  console.error(error);
  process.exitCode = 1;
});
Enter fullscreen mode Exit fullscreen mode

Read before writing.

Use an illustrative tenant, property-company-a, with a customer-owned zone. The record identity in the following model is a local application key. The revision identifies a particular set of desired mail settings. Neither is a provider request field. Actual MX priorities and destinations must come from the company's chosen mail provider; this example deliberately models intent without pretending to supply production MX values.

Here is a runnable TypeScript model using only local state. Save it as a TypeScript file and run it with a TypeScript-capable Node.js runtime. It exercises two attempts and a separate verification transition; it makes no network requests.

type TenantState = {
  zoneId?: string;
  records: Map<string, string>;
  verifiedRevision?: string;
};

const states = new Map<string, TenantState>();
const intent = {
  tenantId: "property-company-a",
  ownership: "customer",
  zoneId: "example-zone-a",
  revision: "mail-config-1",
  recordKey: "company-mail-mx-intent",
};

function provision(): TenantState {
  let state = states.get(intent.tenantId);
  if (!state) {
    state = { records: new Map() };
    states.set(intent.tenantId, state);
  }
  state.zoneId ??= intent.zoneId;
  if (state.zoneId !== intent.zoneId) {
    throw new Error("Zone ownership mapping requires review");
  }
  state.records.set(intent.recordKey, intent.revision);
  console.log(JSON.stringify({
    event: "mail_intent_upserted",
    tenantId: intent.tenantId,
    zoneId: state.zoneId,
    ownership: intent.ownership,
    revision: intent.revision,
  }));
  return state;
}

function verify(state: TenantState, observedRevision: string): void {
  if (observedRevision !== intent.revision) return;
  state.verifiedRevision = observedRevision;
}

const first = provision();
const replay = provision();
if (first !== replay || replay.records.size !== 1) {
  throw new Error("Replay did not converge");
}
verify(replay, "mail-config-1");
verify(replay, "mail-config-1");
console.log(JSON.stringify({
  event: "verification_state",
  verified: replay.verifiedRevision === intent.revision,
}));
Enter fullscreen mode Exit fullscreen mode

The second attempt replaces the same map entry. It leaves one intended record and retains the zone mapping. Verification can then run twice without changing the final result. Those are useful acceptance criteria for a real integration, where the state must survive a process restart and the provider must supply the observations used by verification. The local observedRevision argument represents that observation boundary; passing a string in this model does not verify real DNS.

The subtle trap is a successful remote write followed by an interrupted local save. Persisting the zone identifier after success is necessary, but a crash can still occur between those actions. Design the adapter's recovery around its documented idempotency and lookup behavior. Do not assume that a local tenant key, by itself, makes a remote create safe to repeat. Likewise, a record upsert needs a stable record identity: generating a new identity for every attempt defeats the intended convergence. Consider two workers holding the same tenant job: both can observe an empty local zone field before either has saved a result. A local read followed by a write does not settle that race. The production design needs coordination around tenant state and a remote operation whose replay contract you have checked. Test this boundary by interrupting the worker after the remote operation succeeds, then replaying the same tenant intent and checking that the recovered zone identifier remains stable.

Make progress visible. Proposed application events should carry tenant identity, zone identity, ownership mode, desired revision, stage, and outcome. Keep an attempt identifier for diagnosis, but do not use it as the identity of the intended write. An attempt changes on replay. The intent should not.

Before: an operator sees two successful jobs and cannot tell whether company mail is ready. After: the operator sees that the same tenant and revision reached the record-write stage twice, while verification remains pending. That distinction prevents a retry counter from masquerading as a readiness signal. It also makes a customer handoff legible: pending customer action and a failed authorized write need different responses.

For metrics, aggregate counts by stage and ownership mode; retain tenant and zone details in diagnostic events. Track elapsed time since the desired revision entered verification, and choose an alert threshold that matches the team's onboarding expectations. A repeated verification attempt alone is not an actionable failure. Lack of progress is the signal to investigate.

Limits that matter before a mail change

Idempotency protects repeated intent; it does not authorize a mail migration. A customer-owned zone still needs the customer's authorization. A changed MX destination is new intent, and verification of the previous revision cannot approve it. Keep unrelated records outside the write set, and have the responsible operator review the intended mail changes before applying them.

This model does not implement durable storage, concurrent-worker coordination, provider adapters, or live DNS observation. Those are production requirements to resolve, not properties demonstrated by an in-memory map. Test interrupted persistence and simultaneous attempts before trusting a real onboarding worker.

Finally, MX provisioning and DMARC address different parts of mail operations. RFC 7489 describes DMARC; completing the MX workflow should not be presented as proof that every mail authentication setting is correct. The completion signal should say exactly what was verified.

References

Top comments (0)