Cloudflare / 01
Follow
a request.
Where the address points, whether the request may pass, and what answers it. Pick an architecture, set its one switch, and send.
Illustration The request switchboard
Every request starts with a DNS lookup, before any HTTP; later requests reuse the answer.
- External website. Proxied: the request passes the front door and the cache before the origin. DNS-only: it goes straight to the origin and the front door never sees it.
-
Deployed page. A matching file is served by
Static Assets with no Worker invocation; with
run_worker_firston, the Worker runs first and fetches the asset through its binding. - Public photo. A cached copy answers without reading the bucket; a miss or a purge reads it again.
- Application endpoint. The Worker validates, writes to D1, and answers only after the write result. With Workers Cache on, a second identical GET is answered from the cache and the Worker does not run.
- DNS lookup, before HTTP
- Request or response
- Call through a binding
- Dashed outline: not involved this time
- Path length and timing show dependency, not distance or speed
Inside the endpoint: fetch() against the Cache API
When the Worker runs, it can cache from its own code in two ways. A
fetch() subrequest goes through the zone’s cache,
including tiered cache. The Cache API, caches.default,
is local to one data center and does not use tiered cache, so
another data center will not find what this one stored.
Documented The same response, from two data centers
With fetch(), a request at data center 2 misses its
local cache and finds the copy in the upper tier. With the Cache
API, data center 2 misses and goes back to the origin.
Read the mechanism
Before HTTP
A proxied record answers with Cloudflare anycast addresses, so the browser connects to Cloudflare’s network. A DNS-only record answers with the origin’s own address, and none of Cloudflare’s checks or caching apply. The lookup sees no URL path, cookie or header.
The front door
DDoS protection mitigates floods of traffic; the WAF checks each HTTP request against rules and can allow, block or challenge it. A request that passes is not a signed-in user: your Worker still checks the session, the permission and the input.
Static Assets, unless you say otherwise
A path that matches a deployed file gets the file without invoking
the Worker; a path that matches nothing goes to the Worker.
run_worker_first takes true or a list of
patterns, and a pattern starting with ! excludes paths.
Assets are cached and tiered across Cloudflare’s network.
"assets": {
"directory": "./public",
"run_worker_first": ["/api/*", "!/api/docs/*"]
}
Workers Cache
With "cache": { "enabled": true }, Cloudflare answers a
matching request from the cache without running the Worker. Your
code decides with Cache-Control, followed as RFC 9111
defines it. Only GET and HEAD are cached; a POST always runs the
Worker.
Isolates and bindings
A Worker runs in a V8 isolate that is reused across requests and can be evicted at any time, so a global variable is not state. A binding names one resource in configuration, and code without that binding cannot reach it.
// wrangler.jsonc: "d1_databases": [{ "binding": "DB", … }]
export default {
async fetch(request, env) {
await env.DB.prepare("INSERT INTO photos (title) VALUES (?)")
.bind(title)
.run();
return Response.json({ saved: true }, { status: 201 });
},
};
Sources and limits
Cloudflare pages used
- Proxy status : proxied records return Cloudflare addresses; DNS-only records return the origin’s and bypass Cloudflare’s protection.
- DDoS protection and WAF .
-
Static Assets ,
Worker script routing
and
assets configuration : matching files skip the Worker;
run_worker_first; assets cached and tiered. - Workers Cache : cached responses served without running the Worker; GET and HEAD only.
-
How the cache works :
fetch()and tiered cache; the Cache API is per data center. - How Workers works , bindings , D1 and public buckets .
Documented and illustrated
- Documented: which block each preset’s requests reach, the order of the lookup, front door, cache, Worker and binding calls, the answer after the write result, and the two caches inside a Worker.
-
Illustration:
photos.example.com, the paths, the code samples and route patterns, the four architectures, the two data centers, and every count.
Left out on purpose
- Pricing, latency, throughput, capacity, and size limits. Path length and animation time stand for dependency only.
- How long DNS answers and cached responses are kept; the lab keeps them until you act, change a setting, or purge.
- Individual WAF rules, bot management, and rate limiting.