A healthtech customer wants its own domain on a patient-facing product. The provisioning worker times out, and another attempt starts while the customer changes who controls the zone. The constraint is authority: a retry must still be authorized to make the same change. An upsert alone cannot establish that.
Short answer: design idempotent domain provisioning around a versioned ownership binding, then reconcile authorized DNS changes toward a stored desired state. Use upserts only inside that boundary. For customer-owned zones, produce and verify a scoped change request; for platform-owned zones, apply changes under an explicit record ownership policy. Every retry should converge on the current binding, including a decision to stop when that binding has changed.
This note treats authorization and auditability as the design axis. The example is a proposed onboarding workflow, not a report of a deployment: a fictional tenant, clinic-a, connects portal.clinic.example. Mail authentication remains a separate concern, especially if appointment notices or OTP messages use a customer-controlled sender domain.
How should idempotent domain provisioning handle a retry after ownership changes?
Start with the unit of authority. Store a binding containing the tenant, hostname, authoritative zone identifier, zone controller, and a monotonically increasing generation. Treat a transfer, release, or reassignment as a new generation. An old job must never acquire authority merely because its hostname matches the new request.
Fence stale work.
For this design, the database should enforce one active tenant binding per normalized hostname. Resolve conflicts before scheduling work. Give each accepted desired-state revision a stable operation identifier, and keep transport attempt identifiers separate. Retrying an operation should reuse its identity; changing the intent should create a new revision. Otherwise, a duplicate-request cache can return the result of an obsolete configuration and call that success. A tenant identifier in the request is insufficient: the worker needs the current persisted authorization relationship, not just a caller's assertion that the domain belongs to that tenant.
The controller's ability to edit a zone is also insufficient evidence that a customer may claim a hostname. Make the ownership challenge an explicit prerequisite of activation. For example, the proposed workflow can ask the customer to publish an opaque challenge at a dedicated verification name. Bind that challenge to the tenant and binding generation, and expire it according to a documented policy. Do not put patient names, appointment details, or OTP values in the challenge.
Keep the evidence. An audit record should connect the accepted request, ownership proof, desired-state revision, attempted mutation, and observed outcome. That is a useful compliance control; it is not a claim that DNS verification establishes regulatory compliance.
Derive the upsert from the ownership boundary
Separate desired state from observations. In the proposed model, desired state records exactly which names and record sets the controller may manage. Observations record what was seen, where it was queried, and when. A successful mutation response belongs in the attempt history. It should not overwrite the observation history or immediately activate the customer domain.
Consider three attempts for the same revision. Attempt 1 sends a mutation and loses the response. Attempt 2 observes that the desired record is present and performs no write. Attempt 3 arrives after the binding has been released. It stops. All three outcomes fit idempotency because the controller is converging authorized intent, rather than replaying an instruction regardless of current ownership. These attempt numbers illustrate the design; they are not measured delivery results.
Define the upsert's scope before implementing it. A whole record-set replacement is appropriate only when the controller owns the entire record set. If customers retain control of neighboring or shared records, a reconciliation plan must preserve those records and stop on an ownership conflict. Do not infer permission to replace a set from permission to add one value.
The following Python example deliberately plans one dedicated verification TXT record set. Its inputs are already validated internal values; it does not parse DNS wire data or implement a DNS client. The actual executor must enforce the binding and revision checks at dispatch, under the same serialization boundary used for release and reassignment.
from dataclasses import dataclass @dataclass(frozen=True) class Binding: tenant: str zone_id: str generation: int revision: int active: bool zone_controller: str @dataclass(frozen=True) class VerificationIntent: binding: Binding name: str values: frozenset[str] def plan_verification( intent: VerificationIntent, current_binding: Binding, observed_values: frozenset[str], owns_entire_record_set: bool, ) -> str: if not current_binding.active or intent.binding != current_binding: return "stop_stale_binding_or_revision" if current_binding.zone_controller not in {"customer", "platform"}: return "stop_unknown_controller" if observed_values == intent.values: return "verify_current_challenge" if current_binding.zone_controller == "customer": return "await_customer_change" if not owns_entire_record_set: return "stop_record_ownership_conflict" return "upsert_owned_verification_record_set" A planner is only a gate. It is not a lock.
Persist the planned operation before dispatch, and recheck its revision before executing it. Serialize workers by binding and managed record set. Also define what happens to an external mutation already in flight when a customer releases the binding: a local generation comparison cannot retract a request that has already left the process. In this design, release first blocks new dispatches, drains or resolves in-flight work, and only then permits reassignment. An unresolved mutation keeps reassignment pending for operator review. That trades onboarding speed for a defensible ownership boundary.
Use a dedicated verification name to keep this example's replacement policy narrow. Do not transplant it into a shared mail authentication record set.
Domain activation and message delivery need different evidence
A working product hostname is not evidence that mail sent on a customer's behalf will pass authentication. RFC 7489 defines DMARC policy discovery and identifier alignment: a DMARC pass can result from a passing, aligned SPF identity or a passing, aligned DKIM signature. Treat that as a separate verification path, with its own observations and acceptance criteria.
For a backend handling appointment notifications and OTP messages, this separation changes the release decision. The product-domain state may permit browser traffic while the sender-domain state still requires review. Define which notification paths may proceed at each state; do not silently switch the visible sender identity to bypass an incomplete setup. Publishing DNS policy also does not establish inbox placement.
DMARC discovery uses a TXT record at a name under _dmarc. RFC 7489 also specifies that multiple remaining DMARC records terminate policy discovery without applying DMARC processing. A generic add-another-TXT retry is therefore a bad model for changing DMARC policy. Review the existing policy and its ownership before making any change, and keep this separate from the dedicated verification TXT example above.
Reporting needs its own boundary. RFC 7489 describes aggregate and failure reporting, including authorization checks for external report destinations. Route report configuration through review instead of copying addresses from a generic onboarding template. For healthtech, keep application logs focused on binding identifiers, state transitions, and error categories; exclude patient information and message bodies from this provisioning workflow.
Compare zone control after defining the invariant
The decision is about who can execute and reverse an authorized change. The table describes the proposed operating model, not capabilities promised by a particular service.
| Decision | Customer-owned zone | Platform-owned zone |
|---|---|---|
| Change execution | Customer applies a scoped requested change | Controller applies changes to explicitly managed record sets |
| Retry behavior | Recheck evidence and keep the request tied to its revision | Recheck authority, observe state, then upsert if needed |
| Conflict handling | Ask for review when observed records conflict with intent | Stop when the controller lacks ownership of the entire target set |
| Release | Retire the binding and request cleanup of scoped records | Drain mutations, then remove only records owned by that binding |
Choose the customer-owned path when retaining zone administration is a customer requirement. Budget for a longer pending state and clear support instructions. Choose the platform-owned path only when the operating agreement grants the required control and the team can maintain record ownership, access controls, and a release procedure. Neither choice removes the need to verify the customer's claim.
The staffing trade-off matters more here than a unit-price comparison. Customer-applied changes create support and coordination work; platform-applied changes create credential, audit, and on-call responsibilities. Estimate those workloads from the workflow the team will actually operate. Do not make a provisioning retry policy double as an implicit transfer of zone control.
Roll out with stale work in the test matrix
Begin with a planning-only deployment. Record the proposed action and compare it with an operator-reviewed change for a small pilot cohort. Enable mutation only for dedicated record sets whose ownership is explicit. Keep activation behind observed evidence.
The acceptance tests should cover a lost response after a successful mutation, duplicate jobs, a changed desired-state revision, an ownership challenge from an earlier generation, a conflicting record set, and release while a mutation is in flight. For each case, inspect both the final state and the audit chain. A test that checks only the returned status can miss a stale external write.
Track pending age, conflict counts, retry exhaustion, and time from accepted intent to verified activation. Give each nonterminal state an owner and a bounded retry policy with backoff; exhausting automatic retries should preserve the evidence for review. Avoid recording the raw challenge token when an operation identifier is enough.
Keep rollback scoped. Disable new dispatches, resolve outstanding mutations, and retire or restore only records whose ownership is established. The completion criterion is concrete: the current authorized binding reaches its verified desired state, while obsolete work cannot mutate a newly assigned domain.
Sources
References: the architecture, fictional names, and rollout procedure above are proposed design choices. The mail authentication and reporting requirements are grounded in the following specification, especially Sections 6.6.3, 7, and 7.1.
- RFC 7489, Domain-based Message Authentication, Reporting, and Conformance (DMARC): https://datatracker.ietf.org/doc/html/rfc7489
