Skip to content

Multi-CDN for WordPress: DNS failover vs application-level switching

One CDN is a single point of failure. Two CDNs is an architecture decision: DNS-level failover with NS1 or Constellix, or application-level URL switching from the origin.

A major CDN has a regional outage at 14:00 UTC on a Tuesday. Your site is single-homed on that CDN. Visitors get connection errors for 35 minutes before service is restored. The post-mortem asks why a $50/year SaaS company’s WordPress site can withstand that and yours can’t. The honest answer is that they were running multi-CDN: two providers, DNS or application-level switching, traffic rerouted before most of their visitors noticed. The decision you’re facing is which layer to do the switching at — DNS or application — and the trade-offs are very different.

What’s happening

Multi-CDN means traffic for the same hostname is served from two or more CDN providers, and you have a mechanism to shift traffic between them when one is unhealthy. The two common architectures:

  • DNS-level failover — a smart DNS provider (NS1, Constellix, AWS Route 53, Cloudflare DNS with Load Balancing) returns different A / CNAME answers based on health checks. Healthy provider gets the traffic; unhealthy provider gets pulled. Failover speed is bounded by DNS TTL (typically 30-60 seconds) plus client resolver caching.
  • Application-level switching — every asset URL embedded in HTML is decided at render time. The WordPress origin (or a Worker / edge function) picks cdn1.example.com vs cdn2.example.com based on real-time health or per-request rules. Failover is instant for new page loads, but already-loaded pages keep referencing the dead CDN until the user navigates.

These are not interchangeable. DNS failover is hostname-level — the same hostname (cdn.example.com) resolves to whichever CDN is healthy. Application-level switching uses different hostnames per CDN and rewrites them in HTML.

The trade-offs:

DNS failoverApplication-level
Failover speedTTL + resolver lag (30s–5min)Instant for new requests
Already-loaded pagesRecover on next DNS lookupStuck on dead CDN until refresh
Cache warmth on failoverCold (CDN-B never saw traffic)Cold the same way
Asset URLs in HTMLSingle hostnameDifferent hostnames per CDN
TLS cert provisioningOne cert covers bothPer-CDN provisioning
Health check granularityPer-PoP or per-regionPer-region or per-request
Operational complexityLowerHigher
CostPremium DNS providerWorker/edge function compute

There’s also a third option: active-active load balancing, where both CDNs serve traffic simultaneously based on geo or latency weights. NS1 and Constellix support this with weighted answers and real-time RUM data. For WordPress this is usually overkill unless you’re also doing same-origin failover between two regions.

The cache-warmth problem is the one that bites unprepared teams. CDN-B has no cached entries the moment failover happens. Origin sees a thundering herd of misses across every URL the audience requests. If your origin is a single 4 vCPU VM and your audience is real, origin falls over.

How to verify

Inventory what you have now. If you’re single-CDN, you have zero. If you’ve configured a backup CDN but never tested it, you have a hypothesis. The verifications below assume you’ve built one and want to confirm it actually works.

For DNS failover, simulate CDN-A being unhealthy:

# Health check endpoint your DNS provider polls
curl -sI https://cdn-a.healthcheck.example.com/

# Temporarily fail the health check (e.g., return 503 from origin for that path)
# Watch the DNS records change
dig +short cdn.example.com @8.8.8.8
dig +short cdn.example.com @1.1.1.1
dig +short cdn.example.com @9.9.9.9

The answers should converge on CDN-B within TTL + propagation window (~30-90 seconds for a 30s TTL).

For application-level switching, force a per-request override:

# Origin or worker accepts a header to force which CDN it uses for asset URLs
curl -sI -H "X-Force-CDN: cdn-b" https://www.example.com/ \
  | grep -i link

Then load the page and inspect the rendered HTML’s asset URLs:

curl -s -H "X-Force-CDN: cdn-b" https://www.example.com/ \
  | grep -oE 'https?://[^"]+\.(jpg|jpeg|png|webp|css|js)' \
  | awk -F/ '{print $3}' | sort -u

You should see only cdn-b.example.com hostnames.

For both architectures, verify cache warmth in CDN-B. Use a synthetic warmer (cron or external uptime tool) to pull your top 200 URLs through CDN-B at a regular cadence:

# /usr/local/bin/warm-cdn-b.sh
#!/bin/bash
while read -r url; do
  curl -s --resolve "$(echo "$url" | awk -F/ '{print $3}'):443:$(dig +short cdn-b.example.com | head -1)" \
    -o /dev/null -w "%{http_code} %{time_total} $url\n" \
    "$url"
done < /etc/cdn/top-urls.txt

Run this hourly. If CDN-B’s hit ratio on these URLs is above 90%, the warm-up is doing its job.

The fix

Option A — DNS-level failover with NS1

NS1’s Filter Chain is the relevant feature. Each A/CNAME answer in a record can be tagged with health-check IDs and metadata.

# Use NS1's API or Terraform. Example with curl.
NS1_API_KEY="<your-key>"

# 1. Create monitoring jobs for each CDN
curl -sH "X-NSONE-Key: $NS1_API_KEY" -H "Content-Type: application/json" \
  -d '{
    "name": "cdn-a healthcheck",
    "job_type": "tcp",
    "active": true,
    "frequency": 30,
    "regions": ["lga","ams","sin"],
    "config": {
      "host": "cdn-a.example.com",
      "port": 443,
      "send": "GET /healthz HTTP/1.0\r\n\r\n",
      "response": "200 OK"
    }
  }' https://api.nsone.net/v1/monitoring/jobs

# 2. Create the record with answers tagged by CDN
curl -sH "X-NSONE-Key: $NS1_API_KEY" -H "Content-Type: application/json" \
  -d '{
    "zone": "example.com",
    "domain": "cdn.example.com",
    "type": "CNAME",
    "ttl": 30,
    "answers": [
      {"answer": ["cdn-a.kxcdn.com"], "meta": {"up": {"feed":"<cdn-a-job-id>"}}},
      {"answer": ["example-com.b-cdn.net"], "meta": {"up": {"feed":"<cdn-b-job-id>"}}}
    ],
    "filters": [
      {"filter": "up", "config": {}},
      {"filter": "select_first_n", "config": {"N": 1}}
    ]
  }' https://api.nsone.net/v1/zones/example.com/cdn.example.com/CNAME

The up filter drops any answer whose health-check feed is down. select_first_n picks the first remaining answer. Order in the answer list is your preference (CDN-A is primary, CDN-B is backup), but you can also weight by RUM data if you have it.

Option B — DNS-level failover with Constellix

Same architecture, different syntax. Constellix calls it ITO (Intelligent Traffic Optimization) and uses Sonar health checks.

# Constellix REST API
CNS_KEY="<key>"
CNS_SECRET="<secret>"
TS=$(date +%s000)
HMAC=$(echo -n "$TS" | openssl dgst -sha1 -hmac "$CNS_SECRET" -binary | base64)

# Create a Sonar TCP check
curl -sH "x-cns-security-token: $CNS_KEY:$HMAC:$TS" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "cdn-a-tcp",
    "host": "cdn-a.example.com",
    "port": 443,
    "protocol_type": "TCP",
    "checkSites": [10,4,1],
    "interval": "ONEMINUTE"
  }' https://api.dns.constellix.com/v1/monitor/tcp

# Then create a Failover pool referencing the health checks

Constellix’s strength is the granular per-PoP health view; the limitation versus NS1 is that the filter language is less expressive.

Option C — Application-level switching with a Worker

Pick a default CDN at the WordPress filter layer, with an override that an edge worker can flip via a header or KV value:

<?php
// wp-content/mu-plugins/sh-cdn-router.php
define('SH_CDN_PRIMARY',  'cdn-a.example.com');
define('SH_CDN_BACKUP',   'cdn-b.example.com');
define('SH_CDN_KILLFILE', '/var/lib/sh/cdn-primary-disabled');

function sh_active_cdn(): string {
    // Killfile drops to backup without a code change
    if (file_exists(SH_CDN_KILLFILE)) return SH_CDN_BACKUP;
    // Optional: respect a request-level override (used in tests)
    if (!empty($_SERVER['HTTP_X_FORCE_CDN']) && $_SERVER['HTTP_X_FORCE_CDN'] === 'backup') {
        return SH_CDN_BACKUP;
    }
    return SH_CDN_PRIMARY;
}

add_filter('upload_dir', function($dirs) {
    $host = sh_active_cdn();
    $dirs['baseurl'] = 'https://' . $host . str_replace(home_url(), '', $dirs['baseurl']);
    $dirs['url']     = 'https://' . $host . str_replace(home_url(), '', $dirs['url']);
    return $dirs;
});

add_filter('the_content', function($html) {
    $host = sh_active_cdn();
    return preg_replace(
        '#https?://(www\.)?example\.com(/wp-content/uploads/[^"\']+)#',
        'https://' . $host . '$2',
        $html
    );
}, 99);

The killfile pattern lets operations flip CDNs in one shell command:

# Cut over to backup
sudo touch /var/lib/sh/cdn-primary-disabled

# Restore
sudo rm /var/lib/sh/cdn-primary-disabled

For a smoother failover, replace the file check with a query against a small Redis or etcd value, written by your monitoring system when health checks fail.

Both options — warm the backup

Schedule a warming cron that walks your top URLs through CDN-B every hour. This is the difference between a backup that takes 30s to switch and a backup that survives the cutover:

# /etc/cron.d/sh-cdn-b-warm
*/15 * * * * www-data /usr/local/bin/warm-cdn-b.sh > /var/log/cdn-warm.log 2>&1

The warming script lives in the verification section above.

The decision

DNS-level failover is the right choice if:

  • Your site is mostly anonymous traffic with long-lived sessions are rare.
  • You can tolerate a 30-90s window of broken responses for cached pages.
  • You don’t want to maintain code paths for CDN switching.

Application-level switching is the right choice if:

  • You have a Worker / edge compute platform already in front of WordPress.
  • You can accept the operational cost of maintaining per-CDN URLs and certificates.
  • You need instant failover for ad-supported or commerce pages where 30s of breakage is real money.

Most WordPress operations land on DNS failover with a warming cron — it covers 90% of the value at lower complexity.


Stack Harbor designs multi-CDN topologies for Enterprise WordPress under monitoring and on-call coverage from monitoring and support. If you’re single-CDN and the last incident at your provider made you nervous, start with a resilience review.