DEV Community

EthanBrooks1647
EthanBrooks1647

Posted on

Commerce Tenant Subdomain Signup CNAME Rollback Costs and Retention Explained

The bill to provision a tenant subdomain during storefront signup includes CNAME changes, reconciliation attempts, retained rollback evidence, and the time an engineer spends deciding whether a record can safely be removed. For a concrete planning example, assume 100 unfinished signups each receive seven reconciliation attempts: that creates 700 attempts. Limiting each signup to three automatic attempts reduces that term to 300, while sending the remaining uncertainty to an explicit review queue. Those are scenario inputs, not measured traffic or provider limits. The change buys fewer automatic operations at the expense of more manual decisions.

Short answer: commit the tenant reservation and a durable CNAME provisioning intent together, then reconcile DNS outside the signup database transaction. Keep enough evidence to compensate only the change that signup owns. For an e-commerce customer bringing an existing domain, default to customer-owned DNS unless the customer deliberately delegates control; reserve automatic record removal for names and changes the platform is authorized to manage. A rollback request should become durable recovery work, not an assumption that an external write vanished when the database rolled back.

What actually dominates the recovery bill?

Use a small cost model before choosing a retry policy. Let N be unresolved signups, A the attempts allowed per signup, E the retained evidence size per attempt, and D the retention duration. The attempt count is N × A. Under a deliberately simple policy that keeps every attempt for the same duration, evidence storage over time is proportional to N × A × E × D. Human review is another term: unresolved cases multiplied by review time. This model identifies the knobs; it does not establish which one dominates a production bill without observations.

In the opening example, repeated work is the dominant counted operation: 700 attempts for 100 unfinished signups. A cap reduces that count, but it cannot establish that an ambiguous write failed. A practical proposed policy is three automatic attempts, followed by reconciliation review. Retain the latest desired state separately from attempt history so expiring old attempts does not erase the work still owed.

Count uncertainty explicitly.

For this storefront flow, collect the age of the oldest pending intent, attempts per intent, compensation conflicts, and completed reservations still waiting for verification. Keep these measurements separate from shopper-facing checkout events. A tenant waiting for a domain is a provisioning problem; a failed order is a different incident with a different recovery owner.

Customer ownership determines what rollback may touch

Consider the illustrative store Cedar Basket, whose customer wants shop.cedarbasket.example to identify its storefront. The central decision is who controls the zone containing that name. Under customer-owned DNS, the proposed flow records the requested hostname and gives the customer the intended CNAME target. It then waits for evidence that the requested mapping is present. Cancellation withdraws the platform reservation; removal of the customer's record remains a customer action unless separate write authority has been granted. There is no platform DNS write to compensate in that manual flow.

Platform-owned zones permit a different contract. A reserved name such as cedar.stores.example can enter a managed provisioning queue, and the platform can authorize writes and compensations within that namespace. This reduces the number of customer actions, but it also makes the platform responsible for coordinating concurrent workers, stale requests, and cleanup. Neither control model eliminates recovery work. It changes who can perform it and what evidence must survive.

An existing customer domain deserves extra caution because storefront routing and email authentication have different scopes. RFC 7489 defines DMARC policy discovery using DNS TXT records and distinguishes an Author Domain from its Organizational Domain. A storefront mapping should therefore never be treated as evidence that the platform may rewrite the customer's email policy. Request authority for the particular storefront name and operation. Keep mail policy outside that grant.

For email or OTP notifications about onboarding, the proposed application should keep the delivery status separate from domain readiness. A sent notification is not the evidence that authorizes activating the storefront. This separation also prevents an email delivery delay from silently changing the DNS recovery decision.

Can a signup transaction safely provision a tenant subdomain?

A database transaction in this design commits two things: the tenant's unique hostname reservation and a provisioning intent. The DNS worker runs after that commit. The signup response can report a pending address, while activation waits for the readiness checks chosen by the application. If the caller needs immediate activation, it must accept that signup can remain incomplete while those checks are pending. The transaction boundary does not expand just because the endpoint waits longer.

Give each reservation a generation and keep its state transitions durable. A worker must check that generation before acting. Otherwise, an old cancellation can arrive after a customer has restarted signup and remove the new attempt's mapping. A proposed activation rule is that only the current generation may advance from pending to ready; cancellation records a compensating intent for that same generation.

The recovery evidence should include the exact owner name, record type, previous record state, intended record state, and reservation generation. An upsert that replaces a record needs a restore plan. A create needs a removal plan. Treat an unknown outcome as unknown until a fresh read and the recorded intent can resolve it. In particular, a timeout after a write is insufficient evidence for blindly issuing its inverse.

Keep a separate checkpoint for whether a write was attempted.

A minimal compensation decision in Python

The following example covers a platform-managed name with an initially absent or exclusively CNAME record state. It is a pure decision function, not a DNS client. Its input is a fresh observation of the complete record state managed by the adapter, including all values and the TTL. A production adapter must reject unsupported record layouts before reaching this function.

from dataclasses import dataclass
from typing import Optional


@dataclass(frozen=True)
class Cname:
    target: str
    ttl: int


@dataclass(frozen=True)
class Intent:
    hostname: str
    generation: int
    before: Optional[Cname]
    desired: Cname


@dataclass(frozen=True)
class Decision:
    action: str
    replacement: Optional[Cname] = None


def plan_compensation(
    intent: Intent,
    current: Optional[Cname],
    active_generation: int,
    has_exclusive_write_authority: bool,
) -> Decision:
    if intent.generation != active_generation:
        return Decision("skip_stale_generation")
    if not has_exclusive_write_authority:
        return Decision("request_owner_review")
    if current == intent.before:
        return Decision("already_restored")
    if current != intent.desired:
        return Decision("review_conflicting_record")
    if intent.before is None:
        return Decision("delete_created_record")
    return Decision("restore_previous_record", intent.before)


intent = Intent(
    hostname="cedar.stores.example",
    generation=4,
    before=None,
    desired=Cname("ingress.stores.example", 300),
)
decision = plan_compensation(
    intent,
    current=intent.desired,
    active_generation=4,
    has_exclusive_write_authority=True,
)
assert decision.action == "delete_created_record"
assert plan_compensation(
    intent, intent.desired, 5, True
).action == "skip_stale_generation"
assert plan_compensation(
    intent, intent.desired, 4, False
).action == "request_owner_review"
Enter fullscreen mode Exit fullscreen mode

The TTL of 300 seconds is an illustrative input, not a recommended value or a promise about readiness. The assertions demonstrate three decisions: a created record can be selected for deletion, a stale generation is ignored, and lack of exclusive authority requires review. Extend validation to replacement restoration and conflicting observations before deploying an adapter.

There is a deliberate boundary here. Comparing the current record with the intended record does not prove who wrote it. Another actor could write the same value, or change it between observation and execution. Only execute the proposed compensation under a control arrangement that excludes competing writers for that name, or an adapter contract that can enforce the required conditional mutation. A database lease alone cannot exclude an external administrator. Without that guarantee, preserve the evidence and request review.

This design has a limitation: it doesn't support safe automatic rollback when independent writers can change the same name without conditional mutation. The trade-off is slower manual recovery in exchange for avoiding an unjustified deletion. Use customer-controlled changes when exclusive platform authority isn't available.

A useful failure exercise interrupts the worker after the DNS write but before its completion checkpoint. Restart it and verify that reconciliation can inspect the observed state and converge without deleting an unrelated record. Also cancel a reservation, create a later generation, then deliver the old cancellation. That exercise tests the recovery boundary more directly than a happy-path signup demonstration.

Keep the obligation and expire the noise

Deploy this flow with pending state visible to support staff and a review destination for exhausted retries. A retry cap without an owner merely moves the backlog out of sight. For customer-owned zones, the review action should identify the requested record change and the party authorized to make it. For platform-owned names, it should expose the generation, desired state, prior state, and conflicting observation needed to decide the next action. Avoid placing authentication secrets or shopper information in that record.

Choose retention by the recovery question each record answers. The current intent and its necessary before-state must survive while compensation is still owed. Finished attempt logs can have a shorter, explicitly documented lifetime. Review those lifetimes against the organization's compliance obligations; DNS provisioning does not justify retaining unrelated customer data.

The proposed policy deliberately stops keeping duplicate successful read results and verbose attempt payloads once the recovery evidence is complete. It retains the compact final decision and the state needed for unresolved work. The cost of deleting that detail is real: during a later incident, the team can reconstruct the intended change but may be unable to replay every intermediate observation. Accept that loss explicitly. If the remaining evidence cannot justify a destructive rollback, keep the name reserved for review rather than guessing.

Further reading

References:

Top comments (0)