A signup completes at 10:03. Minutes later, the on-call page says a new developer-tools tenant is sending mail without aligned authentication. The tenant exists in the application database, but its DKIM selector CNAME either has not appeared or still resolves to the old target. The signup request returned success, so the customer quite reasonably expects mail to work.
That is too late.
TL;DR: do not place a DNS API call inside a database transaction and pretend the pair commits atomically. Commit the tenant plus a durable, uniquely keyed DNS intent; let a worker perform an idempotent CNAME upsert; observe authoritative DNS before allowing mail cutover; and compensate by restoring the prior record or deleting the newly created record when the workflow is cancelled. DNS propagation is an observable distributed process, not a rollback-capable database write.
This distinction matters for SPF, DKIM, and DMARC. SPF and DMARC are TXT-based policies, while a DKIM selector can use a CNAME to delegate lookup to a stable target. RFC 7489 defines DMARC policy and reporting on top of SPF and DKIM results. A CNAME upsert alone therefore does not mean the domain is ready; readiness means the expected authentication records resolve and the mail path produces the intended alignment.
How should signup provision a tenant subdomain inside a transaction?
The late page is usually a state-model failure before it is a DNS failure. If the application has only active and failed, signup is forced to call a tenant active before external state can be observed. A timeout makes matters worse: the DNS service may have accepted the change even though the client never received the response. Blindly retrying a create can conflict; blindly deleting during rollback can remove a record that predated this signup.
The response is ambiguous.
Work backward from the alert. The page says mail authentication is unhealthy, but the earlier signal should have been a provisioning SLO violation: a domain remained in applying or verifying beyond its allowed window. Instrument age by state, attempts, last error class, and observed DNS value. Page on sustained customer-impact risk; send an ordinary work-queue alert for a transient API timeout. The two conditions have different urgency.
The state machine needs at least pending, applying, verifying, ready, compensating, and failed. Keep the desired CNAME, the value observed before mutation, and whether the workflow created the record. That small audit trail is the difference between compensation and destructive guessing.
The transaction boundary is an outbox
A relational transaction can atomically insert the tenant and its provisioning intent. It cannot atomically commit a change at an authoritative DNS service. Holding the transaction open during a network call increases lock time while buying no atomicity; if the process dies after the remote write but before the local commit, the systems still disagree.
Use an outbox row with a uniqueness constraint such as (tenant_id, record_name, record_type). Signup writes the tenant, desired DNS state, and outbox event in one commit. A worker claims the event, reads the current record, records that prior state, and issues an upsert with an idempotency token if the DNS interface supports one. If it does not, read-before-write plus deterministic desired state makes retries convergent, although concurrent writers still require a single owner or compare-and-set semantics.
Here is the trade-off I would put in a roadmap review:
| Approach | Signup latency | Failure recovery | On-call cost | Lock-in |
|---|---|---|---|---|
| Synchronous DNS call in signup | Highest and variable | Ambiguous after timeout | High | Tied to client behavior |
| Transactional outbox plus worker | Stable local commit | Retry and compensate | Moderate | Low behind an interface |
| Fully managed workflow engine | Stable local commit | Durable retries and history | Lower runtime toil, higher integration work | Medium to high |
I would start with an outbox when the team already operates a database and queue. I would buy orchestration when long-lived retries, operator visibility, and workflow volume justify transferring that operational burden. The capacity question is concrete: size workers for peak signup rate multiplied by DNS operations per tenant, then reserve retry headroom. An average-rate estimate isn't enough during a launch or tenant migration.
A minimal idempotent worker
The interface below is deliberately generic. A Node.js signup service can write the same outbox contract; the worker language does not change the consistency boundary. The important details are the stable operation ID, capture of prior state, and a separate observation step.
package provisioning import ( "context" "errors" "time" ) type Record struct { Name string Type string Value string TTL time.Duration } type DNS interface { Lookup(ctx context.Context, name, recordType string) (*Record, error) Upsert(ctx context.Context, operationID string, record Record) error Delete(ctx context.Context, operationID, name, recordType string) error } type Job struct { ID string Desired Record Prior *Record Created bool } var ErrNotFound = errors.New("record not found") func Apply(ctx context.Context, dns DNS, job *Job) error { prior, err := dns.Lookup(ctx, job.Desired.Name, job.Desired.Type) if err != nil && !errors.Is(err, ErrNotFound) { return err } job.Prior = prior job.Created = errors.Is(err, ErrNotFound) // Persist Prior and Created before Upsert in the real worker. return dns.Upsert(ctx, job.ID+":apply", job.Desired) } func Compensate(ctx context.Context, dns DNS, job Job) error { if job.Created { return dns.Delete(ctx, job.ID+":delete", job.Desired.Name, job.Desired.Type) } if job.Prior == nil { return errors.New("missing prior state") } return dns.Upsert(ctx, job.ID+":restore", *job.Prior) } There is a deliberate comment where persistence belongs. In production, saving Prior and Created must happen before the remote upsert, and the job cannot be acknowledged until that save is durable. Otherwise a crash recreates the exact ambiguity the design was meant to remove. Also attach ownership metadata locally so a later compensator can prove the record belongs to this workflow. Do not encode that proof solely in a DNS value that another system may legitimately change.
Ownership is evidence.
An upsert is not authorization. Reject record names outside the tenant's delegated zone, normalize names consistently, and prevent a tenant from targeting another tenant's label. Limit CNAME targets to the mail-authentication namespace your platform controls. DNS names and values are input, even when they arrive from an internal service.
Observe first, then cut over
The worker's successful response proves only that the control plane accepted a request. Query the authoritative nameservers for the expected CNAME and, separately, use recursive resolution to understand what typical clients can see. RFC 1034 explains why cached data remains usable until its TTL expires. A short pre-cutover TTL can reduce the cache window, but lowering TTL at the moment of cutover does not evict answers already cached under the old, longer TTL. Plan the reduction at least one old-TTL window ahead.
Now the clock matters.
For the mail scenario, verification should cover the whole authentication path: the DKIM selector resolves as intended, the SPF record is syntactically and operationally valid, and the DMARC record exists at _dmarc with the planned policy. Keep mail disabled, or use a deliberately restricted ramp, until those checks pass. A DNS NOERROR response is insufficient if the returned value is wrong.
Measure two intervals: intent-to-authoritative and authoritative-to-ready. The first catches queue or DNS-control-plane trouble. The second captures cache and validation delay. Histograms should be split by record type and zone because one global percentile hides a stalled zone behind healthy traffic. Track the count and oldest age of incomplete jobs too; a percentile has nothing useful to say when no job completes.
Propagation delay versus cutover speed is a risk choice, not a magic TTL. Lower TTLs can increase query load and shorten future cache lifetimes. Higher TTLs reduce repeated lookups but lengthen rollback visibility. Pick the readiness deadline from the customer promise, then verify that authoritative capacity, recursive-query behavior, retry budget, and support response can sustain it.
Rollback is another forward operation
A database rollback cannot rewind caches. Compensation writes the prior desired DNS state, then waits for that state to become observable. If signup is cancelled before apply, mark the intent cancelled and let the worker skip it. If cancellation races with apply, serialize transitions by job version and move through compensating; do not let two workers alternate desired values.
Rollback is delayed.
Retries need exponential backoff with jitter and a terminal review state, but terminal should mean automatic attempts stopped, not that the domain vanished. Reconciliation must periodically compare durable desired state with authoritative observations. It catches lost queue messages, partial operator edits, and outcomes that arrived after a client timeout.
Be conservative with alerts. A threshold below normal propagation behavior creates pages that cannot produce useful action, teaches the on-call to distrust the signal, and adds load through manual retries. A threshold so loose that unsigned or misaligned mail can begin first is worse. The practical alert fires when the remaining cutover budget is threatened and includes tenant, record name, desired value, observed value, state age, and last classified error. That is enough to act without opening three systems during an incident.
The invariant is narrow: a tenant may be locally committed while DNS is pending, but it must not be declared mail-ready until the expected records are observed. Once that invariant is explicit, signup stays fast, retry behavior is explainable, and rollback stops being a hopeful delete.
