Tiered Caching and Origin Shield
A CDN has hundreds of edge locations, and each keeps its own cache. For a popular page, every edge quickly holds a copy. For the rarely visited majority of a static site — the 1,800 documentation pages that each get a handful of views a day from around the world — most edges never see enough requests to keep a copy warm, especially when HTML has a short lifetime so deploys show up quickly. Each of those misses travels to the origin: an S3 bucket in one region, a small VM, a Pages project. Readers far from the origin wait for the round trip, and the origin serves far more traffic than a "cached" site should.
Tiered caching fixes this by putting a smaller number of upper-tier caches between the edges and the origin. An edge miss asks the upper tier first; only an upper-tier miss goes to the origin. This guide enables it on Cloudflare (Tiered Cache) and CloudFront (Origin Shield), explains how to pick the tier location, and measures the effect on a 2,300-page documentation site with a global audience. It is part of CDN Caching Rules for SSGs.
Prerequisites
- A static site behind Cloudflare or CloudFront with correct cache headers — hashed assets
immutable, HTML revalidated or with a short edge TTL, as in Stale-While-Revalidate for Static HTML. - CDN logs or analytics that show cache status and origin requests.
- Knowledge of where the origin is and where readers are.
Why Rarely Visited Pages Miss
On the documentation site, the top 100 pages received 52% of views and the remaining 2,200 pages the other 48%. HTML had an edge TTL of 10 minutes with stale-while-revalidate, so deploys appeared quickly. For a page viewed 20 times a day, spread over 300 edge locations, almost every view was the first at its edge within the TTL window — a miss. The measured edge hit ratio for HTML was 71% overall and 38% on pages outside the top 100.
How the Tiers Work
With tiering, requests flow in three steps:
- The reader's nearest edge checks its cache. Hit: done.
- On a miss, the edge asks its upper tier — a regional data centre that serves many edges. Hit: the edge stores a copy and responds.
- On an upper-tier miss, the upper tier fetches from the origin, stores a copy, and passes it down.
Because hundreds of edges share a handful of upper tiers, an upper tier sees enough traffic to keep even rarely visited pages warm. And because concurrent requests for the same object are collapsed at the tier, a burst of traffic after a deploy produces one origin request per object instead of one per edge.
Step 1: Cloudflare Tiered Cache
On Cloudflare, Tiered Cache is a zone setting. Smart Tiered Cache, available on all plans, picks the upper tier closest to the origin based on latency measurements; Generic Global Tiered Cache uses several upper tiers; Regional Tiered Cache (Enterprise) adds a middle layer.
curl -X PATCH "https://api.cloudflare.com/client/v4/zones/$ZONE_ID/cache/tiered_cache_smart_topology_enable" \
-H "Authorization: Bearer $CF_API_TOKEN" -H "Content-Type: application/json" --data '{"value":"on"}'
Or in Terraform with cloudflare_tiered_cache { zone_id = …, cache_type = "smart" }. For sites on Cloudflare Workers static assets or Pages, the static files are already served from Cloudflare's storage close to the edge, so tiered caching mainly helps when the zone proxies an external origin such as S3 or a VM. The documentation site proxied a Frankfurt S3 bucket through a Cloudflare zone, the case where it matters most.
Step 2: CloudFront Origin Shield
On CloudFront, Origin Shield is enabled per origin and needs a region. Choose the AWS region closest to the origin — for an S3 bucket in eu-central-1, choose eu-central-1:
"Origins": { "Items": [{
"Id": "docs-s3",
"DomainName": "docs-bucket.s3.eu-central-1.amazonaws.com",
"OriginShield": { "Enabled": true, "OriginShieldRegion": "eu-central-1" },
"S3OriginConfig": { "OriginAccessIdentity": "" },
"OriginAccessControlId": "E2QWRUHAPOMQZL"
}]}
CloudFront already has regional edge caches between edges and origins by default; Origin Shield adds one more centralized layer in front of the origin. It is billed per request that reaches the shield, so it pays off when it significantly reduces origin requests — heavily with S3 cross-region data transfer, less so for an origin in the same region as most readers.
Step 3: Choosing the Tier Location
The upper tier should be close to the origin, not to the readers: the expensive and slow part is the trip to the origin, and a tier near the origin makes that trip short while remaining reachable from all edges over the CDN's backbone. Placing CloudFront's shield in us-east-1 for a Frankfurt bucket in an early test made things worse for European readers — edge misses crossed the Atlantic twice — and origin requests fell by less than with the shield in eu-central-1.
Deploys and Purges With Tiers
Tiers add a cache layer that purges must reach. Both Cloudflare and CloudFront purge upper tiers along with edges, so a purge after deploy works as before, as in Purging the CDN Cache After a Static Deploy. What changes is the refill: after a purge, the first request per object in each tier region goes to the origin, and every edge after that fills from the tier. On the documentation site, origin requests in the ten minutes after a full purge fell from about 48,000 to 6,500 with tiering, which removed the origin load spike that had occasionally caused S3 throttling (503 SlowDown) on large deploys.
Watch one more thing after enabling tiers: the cache status field in logs gains new values (Hit from the upper tier appears as a hit at the edge on Cloudflare, while CloudFront reports Hit or RefreshHit at the edge and records shield hits separately), so dashboards that computed hit ratio from edge status alone may need adjusting to count tier hits correctly.
Measured Impact
Two weeks before and after enabling Smart Tiered Cache on the Cloudflare zone in front of the Frankfurt bucket:
| Measure | Edges only | Smart Tiered Cache |
|---|---|---|
| HTML hit ratio (edge + tier) | 71% | 95% |
| Rarely visited page hit ratio | 38% | 91% |
| Origin requests per day | 118,000 | 17,000 |
| S3 GET requests and egress cost per month | 61 USD | 11 USD |
| TTFB p75 for edge misses, APAC readers | 310 ms | 120 ms |
| LCP p75, APAC readers | 2.2 s | 1.8 s |
| Origin requests in 10 min after full purge | ~48,000 | ~6,500 |
Pitfalls & Rollback
- Tier far from the origin. Adds a long hop and saves little; keep the tier near the origin.
- Expecting tiering to fix bad headers.
no-storeor cookie-varying responses are not cached at any tier. - Paying for Origin Shield without measuring. When the origin is already close and cheap, the extra request charges can exceed savings.
- Fragmented cache keys. Tiers multiply the benefit of a clean key; fix query-string fragmentation first, as in Cache Keys and Query Strings on CDNs.
- Rollback: both features are single settings; disabling them returns to edge-only caching immediately.
Conclusion
Tiered caching is the missing piece for static sites with many rarely visited pages and a global audience: edge misses are served from a regional tier near the origin, so the origin sees a fraction of the traffic and distant readers get faster first views. Put the tier next to the origin, fix the cache key first, and measure origin requests and miss latency. On this site it cut origin requests by 86% and TTFB on edge misses by more than half.
FAQ
What is tiered caching?
A CDN setup where edge locations that miss the cache ask a smaller set of upper-tier or regional caches before going to the origin. Only a miss at the upper tier reaches the origin, so origin requests fall and edges in regions with little traffic get warm content faster.
What is an origin shield?
CloudFront's name for a designated regional cache that all edge locations use as their upper tier for a distribution. It collapses requests from many edges into one request to the origin per object.
Do static sites benefit from tiered caching?
Yes, especially sites with a global audience, many pages that each get modest traffic, short HTML cache lifetimes that expire often, and origins that are slow or charge for egress, such as object storage in a single region or a small VM.
Does tiered caching add latency?
On an upper-tier hit it adds one hop between the edge and the tier, typically 20 to 60 milliseconds, but saves the much longer trip to a distant origin. On an edge hit nothing changes. On the site measured here, median TTFB for edge misses fell from 310 to 120 milliseconds.
Related
- Parent: CDN Caching Rules for SSGs — the full caching strategy.
- Cache Keys and Query Strings on CDNs — fixing fragmentation first.
- Caching 404s and Redirects at the Edge — other responses that reach the origin.
- Alerting on Cache Hit Ratio Drops — keeping the ratio high.
- Improving TTFB for Static HTML — TTFB beyond caching.
Filed underHow-tosCloudflareAWS (S3 and CloudFront)