Cloudflare CDN
medium 24 minCloudflare is a reverse proxy that runs in hundreds of cities behind the same anycast addresses.
Video lesson · Chapter 1 of 5
The same album cover in two cities
Cloudflare CDN in 75 seconds
1:15Reel coming soon
Theory
Read or listen first. About 2 min.
What it is
Cloudflare CDN is a network of data centres that stands between visitors and your server. When you proxy a hostname through Cloudflare, its DNS name points at Cloudflare addresses, and every visitor talks to Cloudflare instead of to you. Cloudflare answers from its cache when it can and asks your server, the origin, when it cannot.
Two design choices make it different from many other networks. The same addresses are announced from every city, which is called anycast, so the internet's own routing brings each visitor to a nearby data centre. And every data centre runs every service: DNS, TLS, attack filtering, the cache, and your own code.
Why it exists
A page served from another continent spends most of its time travelling. A copy in a nearby city removes that journey and removes work from the origin at the same time. The general idea belongs to CDN; this page is about the product.
Because all traffic already passes through, it is also a natural place for security. An attack is spread over many data centres and dropped there, and the origin only sees requests that passed the checks.
A short history
2009
Cloudflare is founded. The idea grew out of Project Honey Pot, which the founders had used to study the source of email spam since 2004.
27 September 2010
Cloudflare launches in public at the TechCrunch Disrupt conference.
2024
Cloudflare announces Instant Purge: tags, hostnames and prefixes are cleared worldwide in under 150 ms at the median, and promises those methods to every plan.
18 November 2025
A configuration file used by Bot Management doubles in size and the proxy software fails on it. Customer sites show errors until core traffic recovers at 14:30 UTC.
Words to know
- Origin
- Your own server or bucket: the source of truth.
- Data centre, or PoP
- One Cloudflare site. It terminates TLS, filters, caches and runs code.
- Anycast
- One address announced from many places. Routing picks the place.
- Zone
- One domain and its settings in a Cloudflare account.
- Cache key
- What decides whether two requests get the same copy.
- Edge TTL
- How long Cloudflare keeps a copy. Browser TTL is a separate setting.
- Upper tier
- A data centre that others ask before anyone asks the origin.
- Worker
- Your JavaScript or WebAssembly code, run in every data centre.
How it works
Step through the idea, or press Play.
Anycast brings the visitor. Every data centre announces the same addresses
Understand it
Start here
Stand number 7 in every town
A company lends umbrellas. Every town has one stand, and every stand has the same number: 7. Nobody looks up which town is closest. You open your umbrella, and the wind carries you to the nearest stand 7.
The wind follows the routes of the internet, which are usually but not always the shortest line on the map.
Why
What you get
Reach
Cloudflare's network page lists 348 cities, and it reported passing 500 Tbps of external capacity.
Anycast routing
One address everywhere. If a data centre leaves, routing moves visitors without a DNS change.
Security in the path
DDoS protection at layers 3, 4 and 7 is unmetered on all plans. WAF and rate limiting rules run before the cache.
Low starting cost
A free plan includes the CDN, DNS, certificates and DDoS protection. Add-ons such as Argo are metered.
Simple operations
Most settings are a dashboard switch or an API call, and Terraform covers them all as code.
Code at the edge
Workers run in every data centre, with KV, D1 and R2 for data.
Capacity figures are the total of all ports, not normal traffic. They matter because an attack has to be larger than what the network can absorb before it can reach you.
Path
The path of one request
Two cities, one upper tier, one origin
- 1
Resolve the name
A proxied DNS record returns Cloudflare's anycast addresses, not your server's address.
- 2
Arrive
BGP routes the packets to a nearby data centre. If that site disappears, the same address leads to another.
- 3
Terminate TLS
The data centre holds your certificate. Visitors can use TLS 1.3, HTTP/2 or HTTP/3. Free certificates are issued automatically.
- 4
Filter
DDoS rules, custom rules, rate limits and managed WAF rules run in that order. A blocked request never reaches the cache or the origin.
- 5
Run your code
A Worker on the route sits in front of the cache and may answer, rewrite or pass the request on.
- 6
Look in the cache
A hit is returned at once. A miss takes a lock, so one data centre sends one request per asset.
- 7
Ask the upper tier, then the origin
With Tiered Cache on, only an upper tier contacts the origin. Connections to the origin are kept open and reused.
- 8
Store and deliver
The response is cached on the way back, compressed if useful, and can be changed by rules or a Worker.
A miss, then a hit
Cache
What is cached, and for how long
Cloudflare decides by file extension, not by MIME type. Images, fonts, CSS, JavaScript, archives and similar files are eligible. HTML and JSON are not cached by default; add a cache rule for them. The origin's headers are respected unless a rule overrides them.
Defaults when the origin sends no cache header
| Status | Edge TTL |
|---|---|
| 200, 206, 301 | 120 minutes |
| 302, 303 | 20 minutes |
| 404, 410 | 3 minutes |
| Others | Not cached |
Set-Cookie, and private or no-store responses are not cached by default.Limits that differ by plan
| Free | Pro | Business | Enterprise | |
|---|---|---|---|---|
| Smallest Edge TTL in a rule | 2 hours | 1 hour | 1 second | 1 second |
| Largest cached file | 512 MB | 512 MB | 512 MB | 5 GB by default |
| Purge by tag, host, prefix, all | 5 a minute | 5 a second | 10 a second | 50 a second |
| Burst of those purges | 25 | 25 | 50 | 500 |
| Tiered Cache, smart topology | Yes | Yes | Yes | Yes |
| Regional and custom tiers | No | No | No | Yes |
The cache key is the full URL plus a few headers by default. Cache rules can drop query strings or add headers and cookies. Too few parts and people see each other's pages; too many and almost nothing is shared. The theory is in cache TTL.
Will Cloudflare cache this?
Tiers
Tiered Cache protects the origin
Without tiers, every data centre that misses asks your origin. With tiers, lower data centres ask an upper tier, and only the upper tier asks the origin. It is available on every plan, and it helps most for long-tail files that each city requests rarely but the world requests often.
Requests that reach the origin
Gains
- Far fewer origin requests and connections
- One city's miss fills the copy another city uses
- A larger shared cache keeps rare files longer
- Smart topology picks the best upper tier for your origin
Costs
- A miss travels one hop more
- Changing origin addresses can move the upper tier and cool the cache
- An origin behind anycast hides its place; give a cloud region hint
- Regional and custom topologies need Enterprise
Speed
Argo, HTTP/3 and images
| Feature | What it does | When it pays |
|---|---|---|
| Argo Smart Routing | Uses live network data to route requests around congestion | Visitors far from the origin, dynamic requests |
| HTTP/3 | QUIC over UDP. A lost packet does not block other streams | Mobile and lossy networks. Browsers fall back to HTTP/2 |
| Polish | Strips metadata and compresses images when they are fetched | Image-heavy sites |
| Compression | Sends text in a compressed form the browser accepts | HTML, CSS, JavaScript, JSON |
Argo is like a navigation app that knows today's traffic jams: the destination is the same, but the road is chosen by how fast it is now.
Security
What happens before the cache
Inside one data centre
Layers of protection
- 1
DDoS, layers 3 and 4
Floods of packets are dropped automatically. In the fourth quarter of 2025 Cloudflare reported stopping an attack of 31.4 Tbps that lasted 35 seconds.
- 2
DDoS, layer 7
Floods of real HTTP requests are recognised and challenged or dropped. It is always on.
- 3
WAF
Managed rules look for common attacks such as SQL injection and cross-site scripting; your custom rules run before them.
- 4
Rate limits and bots
Rules count requests by address or other fields and block, challenge or log. See rate limiting.
- 5
Magic Transit
An Enterprise product that carries whole networks, not only HTTP, through the same filters.
Encryption modes
| Mode | Visitor to Cloudflare | Cloudflare to origin |
|---|---|---|
| Off | Plain HTTP | Plain HTTP |
| Flexible | Encrypted | Plain HTTP |
| Full | Encrypted | Encrypted, certificate not validated |
| Full (strict) | Encrypted | Encrypted and validated |
Code
Workers: your code in every data centre
A Worker is JavaScript or WebAssembly that handles a request. Workers run in isolates, light contexts inside one running process, so there is no container to boot for each customer. Use them for redirects, A/B tests, authentication, header changes, or a whole application.
Where a Worker keeps data
| Store | Shape | Know this |
|---|---|---|
| Workers KV | Key-value, read everywhere | Eventually consistent: a write may take 60 seconds or more to appear elsewhere |
| D1 | SQL database with SQLite semantics | Real queries for a site, user or tenant |
| R2 | S3-compatible object storage | No egress fees |
| Durable Objects | One object that owns its state | Use it when you need strong consistency |
A Worker in the path
Change
Getting new content out
Choose how to update
| Method | Reach | Cost or risk |
|---|---|---|
New file name, such as app.3f9a.js | CDN and browsers | None; needs a build step |
| Purge by URL | CDN only | The recommended purge |
| Purge by tag, hostname or prefix | CDN only | All plans; rate-limited by a token bucket |
| Purge everything | CDN only | The whole site must be fetched again from the origin |
| Invalidate | CDN only | Marks copies stale; unchanged files are revalidated, not downloaded again |
How many purges fit in a burst
Failure
When something breaks
Read the signs
| Sign | Meaning | Look at |
|---|---|---|
cf-cache-status: DYNAMIC | Not eligible for cache | Extension and cache rules |
BYPASS | Eligible, but a header or cookie refused it | Set-Cookie, private, no-store |
EXPIRED, REVALIDATED | Copy was old; the origin was asked | TTL and ETags |
STALE, UPDATING | An old copy was served | Origin health, stale rules |
| Error 522 | No TCP connection in time, about 19 seconds | Firewall, origin down |
| Error 524 | Connected, but no answer in 125 seconds | Slow work; make it asynchronous |
cf-ray | Identifier of this request | Quote it to support |
Origin down. Cloudflare can serve stale copies. With Always Online it can also fall back to the Internet Archive, when you switch it on: only popular pages, crawled every 5 to 30 days depending on plan, with a banner. It does not save dynamic pages. Cloudflare's load balancer can move traffic between several origins.
Cloudflare down. On 18 November 2025 an oversized configuration file stopped the proxies from handling traffic, and on 5 December 2025 a change affected customers with about 28% of the HTTP traffic for about 25 minutes. Anycast does not help when the same software fails everywhere. Decide in advance: accept it, or keep a second CDN or a way to point DNS elsewhere, and know that going around the CDN also removes its protection.
Decide
When to choose it
Choose it when
- You want a CDN and security that start simply and free
- Origins are in several clouds or your own building
- The site is global and mostly cacheable
- You want security and code in the same place
- APIs need short TTLs and better routes
- Live video needs worldwide ingest and delivery
Think again when
- Every response is personal and nothing is cacheable (it may still help with TLS and security)
- All users sit next to the origin
- Everything is in AWS and you want its access control and free origin transfer
- Readers must never see an old value
- You need control over each cached entry that rules cannot give
- A policy forbids a third party from decrypting traffic
Compared with others
| Network | Closest in | Differs in | Choose it for |
|---|---|---|---|
| Amazon CloudFront | Edge cache, functions, WAF, HTTP/3 | DNS picks the location; Origin Shield instead of Tiered Cache; tied to AWS | Origins in AWS |
| Fastly | Edge cache, code at the edge, fast purge | Configured in VCL; fewer, larger sites | Fine control of caching in code |
| Akamai | Reach, media, security | Very many small sites; enterprise sales | Large media and enterprise support |
| Google Cloud CDN | Anycast, cache | Attached to Google's load balancer | Origins in Google Cloud |
resource "cloudflare_zone" "site" { account = { id = var.account_id } name = "example.com" type = "full"}resource "cloudflare_dns_record" "www" { zone_id = cloudflare_zone.site.id name = "www.example.com" type = "CNAME" content = "origin.example.net" ttl = 1 # automatic proxied = true # traffic goes through Cloudflare}resource "cloudflare_ruleset" "cache" { zone_id = cloudflare_zone.site.id name = "Cache rules" kind = "zone" phase = "http_request_cache_settings" rules = [{ expression = "starts_with(http.request.uri.path, \"/static/\")" action = "set_cache_settings" action_parameters = { cache = true edge_ttl = { mode = "override_origin", default = 86400 } browser_ttl = { mode = "override_origin", default = 3600 } } }]}Summary
The whole topic in one minute.
Cloudflare is an anycast reverse proxy. A visitor reaches a nearby data centre, passes the security rules, then Workers, then the cache. A miss goes to an upper tier and only then to the origin, and simultaneous misses in one data centre are collapsed into one.
By default it caches a list of static file extensions and not HTML or JSON, so write cache rules. Prefer versioned URLs to purging, use Full (strict) encryption, remember that a purge never reaches a browser, and have a plan for the day the provider itself fails.
- Anycast: the same addresses everywhere, routing chooses the data centre.
- Every data centre runs DNS, TLS, filters, cache and Workers.
- Security runs before the cache; a hit was still checked.
- HTML and JSON are not cached until a rule says so.
- Tiered Cache and the cache lock turn many misses into one origin request.
- Version file names; a purge does not reach browsers.
- Full (strict) encryption, a hidden origin, and a plan for the provider's bad day.
Sources
- Cloudflare: default cache behavior
- Cloudflare: Tiered Cache
- Cloudflare: purge cache and its limits
- Cloudflare: edge and browser cache TTL
- Cloudflare: request phases
- Cloudflare: Workers limits
- Cloudflare: 500 Tbps of capacity
- Cloudflare: outage on 18 November 2025
- Cloudflare: outage on 5 December 2025
- Cloudflare: DDoS report, fourth quarter 2025