Purge CDN Cache Without Causing an Origin Stampede
Invalidate changed assets at the edge with tags, warm the origin first, and confirm the new release is served from every POP without an origin stampede.
Objective
Replace stale content at the CDN edge in a controlled order while protecting the origin from a surge of cache misses and confirming the new release everywhere.
Environment
- A CDN that supports cache tags or surrogate keys in addition to URL purges
- Release metadata that maps each deployment to its asset URLs or cache tags
- Origin capacity data and a pre-warm path for changed assets
- Access to CDN analytics showing cache hit ratio, bandwidth and origin errors
- A verified previous release artifact for rollback
Steps
1. Tag the release and list changed assets
Attach a release tag such as release-2026-10-21 to every changed asset and produce the list of URLs, fonts and API responses affected by the deploy.
Expected state: Every changed asset carries the release tag and no unrelated asset shares it.
2. Check origin capacity and pre-warm
Fetch the changed assets through the CDN from a warm-up client, confirm origin response times, and verify the origin can absorb the expected miss rate.
Expected state: The origin serves the new release within its latency target and cache entries exist for the main entry points.
3. Purge by tag in batches
Invalidate the release tag rather than the whole cache, starting with HTML and entry bundles, then static assets, waiting for each batch to repopulate.
Expected state: Only assets carrying the release tag are evicted and the origin error rate stays flat.
4. Verify from multiple POPs
Request the changed URLs through several edge locations and inspect cache status, age and ETag to confirm the new content is served.
Expected state: Cache status shows a hit or refreshed entry with the new ETag from every tested location.
5. Watch origin and roll back the deploy if needed
Monitor origin 5xx rates, response time and bandwidth for thirty minutes, and if the release is faulty, restore the previous artifact and purge the same tags again.
Expected state: Error budgets remain within target or the previous release is fully restored and cached.
Decision points
Should the purge target everything or only the release?
- Purge everything for certainty
- Purge the release tag or affected URLs
Purge by tag or URL; a full purge sends every visitor to the origin and is the most common cause of a self-inflicted outage.
Should assets be pre-warmed before the purge?
- Warm the main entry points first
- Let traffic repopulate the cache naturally
Warm HTML and entry bundles first when the origin is not autoscaled; static assets with long TTLs can repopulate naturally.
What should happen if the release is faulty?
- Roll back the origin release and purge again
- Leave the new release and patch forward
Roll back and purge the same tags; patching forward while the cache is mixed produces inconsistent behavior across regions.
Expected outcome
The new release is served from every edge location, the cache holds only intended content, and the origin absorbed the refresh without errors.
Verification
Check cache status, age and ETag headers from at least three edge locations, compare the CDN hit ratio with the pre-deploy baseline, and review origin 5xx and latency graphs.
Cleanup
Remove temporary warm-up jobs, keep the previous release artifact for thirty days, and record the purge tag and timestamp in the release notes.
Cache purge is a traffic event
Every evicted object becomes a request to the origin. Purging a site with a cold origin is indistinguishable from a small denial-of-service attack that you launched yourself. Treat a purge as a change with a blast radius: identify what must be replaced, keep the invalidation as narrow as the release metadata allows, and confirm the origin can handle the miss rate before evicting anything.
Purge by tag, not by reflex
A tag-based purge lets you replace exactly the assets from one deploy. The request below invalidates a release tag through the Cloudflare API and then checks what an edge node actually serves.
curl -X POST "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/purge_cache" \
-H "Authorization: Bearer $CF_TOKEN" \
-H "Content-Type: application/json" \
--data '{"tags":["release-2026-10-21"]}'
curl -sI https://www.example.com/app.js \
| grep -iE "cf-cache-status|age|etag|last-modified"
Safety checks
Purge in batches: HTML and entry bundles first, static assets second, media last. Keep the previous release artifact available and confirm that rolling back the origin also reverses the cache key or ETag, otherwise the edge will keep serving the new content. Never purge during a traffic peak or while the origin is deploying. If the CDN supports soft purge, use it for HTML so stale content is served while the edge revalidates.
Verify
Check headers from several POPs, not just the one near your office; a purge is not complete while some regions still serve the old ETag. Watch origin 5xx, latency and bandwidth for thirty minutes.
Rollback
If the release is faulty, restore the previous artifact and purge the same tag again rather than purging everything. The purge itself cannot be undone, but the content can always be republished; the irreversible step is deleting the previous release artifact before the rollback window closes.