Lesson 3 of 9 · 21m
The Request Lifecycle: DNS, TLS, Routing, and Origin Selection
Trace a request through Anycast, TLS termination, Worker execution, cache lookup, and origin routing so debugging starts in the right layer.
When an edge application is slow, inexperienced teams start editing application code. Experienced teams first ask where the request went. Edge systems are pipelines. Latency, failure, and cache behavior can enter at DNS, routing, TLS termination, Worker execution, cache lookup, origin selection, or response delivery. If you cannot draw the request path, you are guessing.
Start with a timeline, not a log line
Use browser timing or curl to separate connection setup from server work:
curl -o /dev/null -sS https://shop.example.net/checkout -w 'dns=%{time_namelookup} connect=%{time_connect} tls=%{time_appconnect} start=%{time_starttransfer} total=%{time_total}
'The names are imperfect but the separation is useful. DNS or connect time indicates network placement and resolution behavior. TLS time indicates handshake cost. Time to first byte includes edge compute and any upstream dependency. Total time adds transfer size and client connection quality.
Anycast chooses a network location, not your architecture
With Anycast, the same IP address is announced from many locations. Routing protocols steer users toward a nearby or otherwise preferred point of presence. “Nearby” is network topology, not geography. A user in Chicago can occasionally land somewhere unexpected because ISP routing is political, economic, and dynamic.
client resolver -> authoritative DNS -> edge IP
client TCP/TLS -> nearest advertised PoP (usually, not guaranteed)
PoP decision -> cache / Worker / originDo not build correctness around perfect geographic routing. Use geography as a latency optimization, never as a hard tenancy or compliance boundary unless the platform contract explicitly supports that enforcement.
TLS is part of application architecture
TLS termination at the edge removes handshake round trips from long-distance paths. It also means the edge sees plaintext requests. That is powerful and dangerous: edge compute can inspect and modify traffic, but compromise or misconfiguration at that layer is application compromise. Certificate automation, cipher policy, and key custody are production concerns, not implementation trivia.
The decision order matters
A representative flow looks like this:
1. receive request
2. terminate TLS
3. normalize host/path/protocol
4. execute security policy or Worker logic
5. compute cache key
6. cache lookup
7. conditionally contact origin or service
8. transform/store/deliver responseChanging that order changes correctness. If authorization executes after cached content is selected, private data can leak. If redirects execute before normalization, you create loops. If cache lookup happens before vary logic is normalized, hit ratios collapse.
Origin selection is a routing policy
“Send the rest to the origin” hides important decisions: which origin, which protocol, which headers, which timeout, what retry behavior, and whether failover preserves correctness. Multi-region origins should be selected deliberately:
const region = request.cf?.region ?? "unknown"
const upstream = region === "Europe" ? env.EU_ORIGIN : env.US_ORIGIN
return fetch(new Request(upstream, request), { cf: { cacheTtl: 0 } })That example is routing, not magic. The application must still handle regional failure, data locality, and write consistency.
Field notes
- Debug with response headers that identify cache status, selected upstream, and decision version, but avoid exposing sensitive internals publicly.
- A redirect loop at the edge often comes from protocol normalization: HTTP-to-HTTPS, host canonicalization, or trailing slash rules fighting each other.
- Do not conflate DNS propagation with edge deployment propagation. They are separate systems with separate timelines.
- Keep one golden
curlcommand per critical route. When support says “slow,” run the timeline before opening the code.
Was this lesson helpful?