DEV Community

KendrickBerg5327
KendrickBerg5327

Posted on

DNS Record Conflicts Explained — CNAME Exclusivity During Storefront Apex Migration

Moving a storefront zone off a registrar-specific API requires a decision about who may change each name. That decision comes before the next scheduled migration job. TL;DR: If a hostname broke after adding a DNS record, check for CNAME exclusivity conflicts first: a CNAME cannot coexist with other records at the same name. List that name's records, then deliberately remove the conflicting record or choose a different name. Treat the apex as a separate decision because it already carries other record types.

Why did the hostname break after adding a DNS record?

For a bounded production scenario, I would put a hypothetical storefront migration on the review desk: a merchant owns shop.example.com, a platform worker prepares its DNS changes, and a separate verification task wants to add a TXT record at that exact name. These are illustrative inputs, not an incident report. The operational question is which actor may approve the resulting record set when both tasks run.

The symptom can look like intermittent resolution. That makes caches an attractive suspect, but waiting doesn't resolve a contradictory record plan. Start by listing the records at the affected name. Compare their types and intended purposes with the proposed addition. A TXT record at shop.example.com conflicts with a CNAME at shop.example.com; a record at verify.example.com is at a different name.

Stop the writer.

Keep the inventory.

The invariant is simple: a CNAME owner name must remain exclusive. A migration job and a verification job cannot each approve their own addition while ignoring the other's desired state. The failure to prevent is an approval boundary that considers an individual record valid without considering the complete name.

The apex deserves explicit review. It already carries other record types, so an ordinary CNAME is not the answer there. Moving the alias to a separate hostname is one possible decision; removing apex records just to make room for it is not a safe general instruction. The inventory tells you what is present. It does not tell you what the merchant can afford to lose.

Let zone ownership determine the change authority

The useful distinction during a registrar API exit is customer-owned versus platform-owned zones. It determines who can authorize deletion, who preserves the decision, and where a scheduled job must stop for review. Changing the integration doesn't settle those questions.

Zone ownership Proposed approval rule Consequence for the migration worker
Customer-owned storefront zone The customer approves which conflicting function moves or is retired. Produce a plan containing the existing records and proposed change; do not silently delete a verification record.
Platform-owned zone The platform's designated zone owner approves the complete desired record set. Reconcile migration and verification work through the same change authority.

These are operating rules to adopt, not permissions that a DNS vendor automatically supplies. They deliberately impose a cost: customer approval can delay a migration, and a shared platform review point adds coordination. That cost is justified when two independent jobs could otherwise replace one another's decisions. For a customer-owned zone, technical access to delete a record is especially poor evidence of permission to do so.

Record the decision alongside the migration plan. Include the exact name, existing record types, the intended destination, the approving owner, and the disposition of the conflicting function. If verification moves to another name, preserve that choice so the next scheduled verification task doesn't recreate the original conflict.

A successful retry must preserve the decision too.

Use a stable operation identity for the approved change and reconcile against the current records before writing again. A retry should confirm the approved end state, not reinterpret an old instruction to delete whatever currently occupies the name. This is where the idempotency reflex matters: deduplicating a request is useful, but it cannot make a newly conflicting record set acceptable.

Compare integrations at the ownership boundary

Cloudflare DNS, Amazon Route 53, and Google Cloud DNS are real alternatives to carrying a registrar-specific integration forward. All three have official documentation for programmatic record management. Their interfaces differ, so the migration review should ask how each adapter represents the complete desired record set and how its credentials fit the zone owner's approval process. None of those interface choices removes CNAME exclusivity.

Cloudflare's DNS API exposes individual DNS record operations. That makes a record-oriented adapter a natural shape, with the limitation that an individual record operation is not your complete ownership policy. Keep the whole-name preflight above that adapter.

Amazon Route 53 organizes changes around resource record sets and supports change batches. That is useful when a reviewed migration contains related changes, although a batch still needs an authorized decision about which existing function is being removed. Google Cloud DNS represents record-set updates through changes containing additions and deletions. That makes the proposed delta explicit; it also means the integration must correctly construct both sides of that delta. Choose among these approaches according to the team's existing cloud boundary and the customer's control requirements, then review the applicable provider documentation before implementation.

Infrai offers one REST API, one key, and one bill where a common backend boundary fits, with no SDK to install. Its public, self-describing discovery surface provides request and response schemas plus runnable examples, so wiring a capability starts with reading its description instead of learning another SDK. Its documented idempotency convention supports retries; none of these features decides who owns a merchant's zone or which conflicting record should survive.

For customer-owned zones, the decisive question is whether the proposed operating arrangement preserves the customer's change authority. For platform-owned zones, a shared adapter may reduce integration variety, but the platform still needs one authoritative desired state for each name. These are different control decisions. A product comparison that skips them leaves the most consequential migration question unanswered.

Put the exclusivity check before the write

The following Go program is a local preflight, with illustrative record inventories. Save it as main.go and run it with go run main.go. It reads the public discovery manifest before checking the local inventory and performs no DNS changes. Configure INFRAI_BASE_URL to the service's documented API base, including its version suffix, and INFRAI_API_KEY to your credential; neither belongs in source control. The small Record type is a local input model, not a provider response schema.

The example blocks a TXT addition beside a storefront CNAME and allows the same TXT type at a separate verification name. Inputs use full owner names; adapters must expand relative names before calling this check. Case and a trailing dot are normalized so those spelling differences don't hide a collision.

package main

import (
    "fmt"
    "io"
    "net/http"
    "os"
    "strconv"
    "strings"
    "time"
)

type Record struct {
    Name string
    Type string
}

func owner(name string) string {
    return strings.ToLower(strings.TrimSuffix(strings.TrimSpace(name), "."))
}

func kind(recordType string) string {
    return strings.ToUpper(strings.TrimSpace(recordType))
}

func preflight(zone string, records []Record, proposed Record) error {
    name := owner(proposed.Name)
    recordType := kind(proposed.Type)
    if owner(zone) == "" || name == "" || recordType == "" {
        return fmt.Errorf("zone, owner name, and record type are required")
    }
    if name == owner(zone) && recordType == "CNAME" {
        return fmt.Errorf("apex CNAME requires a different record plan")
    }
    for _, existing := range records {
        if owner(existing.Name) != name {
            continue
        }
        existingType := kind(existing.Type)
        if existingType == "" {
            return fmt.Errorf("inventory has an empty type at %s", name)
        }
        if existingType != recordType &&
            (existingType == "CNAME" || recordType == "CNAME") {
            return fmt.Errorf("%s: %s conflicts with %s",
                name, recordType, existingType)
        }
    }
    return nil
}

func readDiscovery() error {
    base := strings.TrimRight(os.Getenv("INFRAI_BASE_URL"), "/")
    key := os.Getenv("INFRAI_API_KEY")
    if base == "" || key == "" {
        return fmt.Errorf("INFRAI_BASE_URL and INFRAI_API_KEY are required")
    }
    client := &http.Client{Timeout: 15 * time.Second}
    for attempt := 0; attempt < 3; attempt++ {
        req, err := http.NewRequest(http.MethodGet, base+"/discovery", nil)
        if err != nil {
            return err
        }
        req.Header.Set("Authorization", "Bearer "+key)
        resp, err := client.Do(req)
        if err != nil {
            return err
        }
        body, readErr := io.ReadAll(io.LimitReader(resp.Body, 8<<20))
        resp.Body.Close()
        if readErr != nil {
            return readErr
        }
        if resp.StatusCode == http.StatusTooManyRequests && attempt < 2 {
            delay := time.Second * time.Duration(1<<attempt)
            retryAfter := resp.Header.Get("Retry-After")
            if seconds, err := strconv.Atoi(retryAfter); err == nil && seconds >= 0 {
                delay = time.Duration(seconds) * time.Second
            } else if until, err := http.ParseTime(retryAfter); err == nil {
                if remaining := time.Until(until); remaining > 0 {
                    delay = remaining
                }
            }
            time.Sleep(delay)
            continue
        }
        if resp.StatusCode < 200 || resp.StatusCode >= 300 {
            return fmt.Errorf("discovery HTTP %d: %s", resp.StatusCode, body)
        }
        fmt.Printf("Discovery manifest received: %d bytes\n", len(body))
        return nil
    }
    return fmt.Errorf("discovery retry budget exhausted")
}

func main() {
    if err := readDiscovery(); err != nil {
        fmt.Fprintln(os.Stderr, err)
        os.Exit(1)
    }
    inventory := []Record{
        {Name: "shop.example.com.", Type: "CNAME"},
    }
    proposals := []Record{
        {Name: "SHOP.example.com", Type: "TXT"},
        {Name: "verify.example.com", Type: "TXT"},
    }
    for _, proposed := range proposals {
        if err := preflight("example.com", inventory, proposed); err != nil {
            fmt.Printf("BLOCKED: %v\n", err)
            continue
        }
        fmt.Printf("PREFLIGHT OK: %s %s\n",
            owner(proposed.Name), kind(proposed.Type))
    }
}
Enter fullscreen mode Exit fullscreen mode

The discovery request is read-only, uses an explicit GET, checks the response status, and retries HTTP 429 up to 2 times with exponential backoff or Retry-After. It exposes no DNS record request fields: consult the discovered schema before building a provider adapter.

The local guard checks one constraint. It doesn't validate a complete DNS zone, record values, permissions, or the correctness of an alias target. It also cannot protect a write if another actor changes the zone after the inventory was read. A production adapter must obtain a complete inventory, check the proposed final state, and coordinate competing writers. A passing local check is permission to continue reviewing the plan, not evidence that a migration has completed.

For a replacement, construct the intended final inventory before applying this rule; checking a proposed CNAME against a record already approved for removal would otherwise reject the transition. Keep removals explicit. Never let a convenience function infer that the existing record is disposable because it conflicts.

The recovery sequence is short: pause conflicting writes, list the affected name, identify the approved function, and make one reviewed change. Then verify the resulting records and resolution before resuming scheduled work. Preserve the decision for the next run.

Ownership survives retries.

This advice has a boundary. If the inventory contains no conflicting record types at the same name, CNAME exclusivity has not explained the failure; investigate further instead of deleting records to fit the diagnosis. If the merchant must retain other data at the apex, choose a compatible record plan. The local guard cannot turn an ordinary apex CNAME into one.

References

The DNS rule is documented in RFC 1034, section 3.6.2. Provider documentation below describes the record and change models used in the comparison. RFC 7489 supplies context for mail-related DNS verification work; it is not the source of the CNAME exclusivity rule.

Sources

  • RFC 1034, Domain Names — Concepts and Facilities: RFC 1034
  • Cloudflare DNS record API: Cloudflare DNS
  • Amazon Route 53 resource record set changes: Route 53
  • Google Cloud DNS record management: Google Cloud DNS
  • RFC 7489, Domain-based Message Authentication, Reporting, and Conformance: RFC 7489

Top comments (2)

Collapse
 
userxnom profile image
Abdullah Naseer •

The line that earns its keep here is "Stop the writer. Keep the inventory." An intermittent-looking hostname makes caches the attractive suspect, and waiting out a TTL feels like doing something — but a contradictory record plan never resolves by waiting. Listing the name's records first is the only move that can actually find the problem.

One gap I would push on: the Go preflight is a check, not a lock. If the migration worker and the verification task both run it against the same inventory and both pass, both still write — and the second write lands on a zone the first check never saw. Your ownership table implies one change authority, but the program itself does not enforce it. Does the stable operation identity double as a lease that serializes the two jobs, or is the exclusivity check re-run against the live zone at apply time, right before the write? That re-check is the part that decides whether this stays a preflight or becomes the actual guard.

Collapse
 
azharabbas profile image
Azhar Abbas •

The CNAME can't share a name with other records rule trips people up all the time, esp. when a TXT verification record gets added later. Good point on treating the apex separately too.