Networking
Part 5 of 6 · CDN & edge cacheTLS Termination & Anycast Edge
Edge TLS plus Anycast cuts handshake RTT and shares one VIP worldwide. Trade-off: anycast can flap, keys live at the edge, and origin still needs a private path (mTLS).
- 1Gist
- 2Maps
- 3Q&A
- 4Sandbox
Voice readout needs Web Speech Synthesis in this browser.
Overview
Without an edge, the client's TLS handshake crosses the WAN: 1–2 round trips times 80–200 ms. That budget is TTFB before HTML even starts. A CDN POP terminates TLS a few milliseconds away, speaks HTTP/2 or HTTP/3 with multiplexing, and (on a HIT) never touches origin. Origin connections are a second, long-lived TLS session from shield to origin — hop encryption, not end-to-end privacy from the CDN.
Anycast advertises the same VIP from many POPs. BGP delivers the client to a topologically close POP. Geo-DNS answers different IPs from different resolvers. Most CDNs use both (Anycast for the data plane, DNS for service discovery or mixed steering).
Why edge TLS wins TTFB
| Path | Handshake | First request | Typical first-byte on a HIT |
|---|---|---|---|
| Origin-only TLS (TLS 1.2, origin RTT 100 ms) | ~2 RTT = 200 ms | +1 RTT = 100 ms | ~300 ms plus origin compute |
| Origin-only TLS 1.3 | ~1 RTT = 100 ms | +1 RTT | ~200 ms plus compute |
| Edge TLS 1.3, POP RTT 10 ms, cache HIT | ~1 RTT = 10 ms | +1 RTT = 10 ms | ~20 ms |
| Edge HIT after session resumption / 0-RTT | ~0–1 RTT | often coalesced | single-digit to low tens of ms |
0-RTT (TLS 1.3 early data) is a replay hazard for non-idempotent POST. CDNs enable it carefully; do not blindly turn it on for origin POSTs.
WAF, bot scoring, and HTTP/2 push-or-not all require plaintext at the POP. That is the product. If a threat model forbids the vendor seeing bytes, you do not put that traffic on a shared CDN — or you use a private offering with contractual isolation, not "HTTPS to origin" as a privacy story.
- 1
client → origin WAN RTT per handshake
Origin-only TLS
Every new connection pays origin RTT. No POP cache, no HTTP/3 at the edge, no Anycast failover of the VIP. TTFB is dominated by distance.
- 2
Winner for public sites: edge TLS + Anycast + warm origin TLS
Client handshake is local. POP multiplexes HTTP/2 or HTTP/3. Shield keeps a warm TLS pool to origin. Cold miss pays an extra hop; HIT does not.
- ?
When origin mTLS / private link is still required
If someone discovers the origin IP they must not pull it as an open website. mTLS, allow-listed CDN egress, or a private interconnect. Cleartext-in-VPC is not a substitute.
Anycast vs geo-DNS
| Anycast | Geo-DNS / GSLB | |
|---|---|---|
| Addressing | One IP (or a handful of VIPs) announced from many POPs | Different A/AAAA answers per resolver |
| Who picks the POP | BGP path selection | DNS policy (latency, load, health, map) |
| Failover | Withdraw the prefix from a sick POP; convergence in seconds | Depends on DNS TTL and resolver cache |
| Steering precision | Topological, coarse; "close" ≠ geographic | Finer, but resolver location ≠ client location |
| Failure mode | Route flap mid-flow (especially UDP/QUIC) | Sticky wrong POP until TTL; EDNS client-subnet variance |
Anycast flap. Severe routing changes can move the next packet to another POP. TCP often RSTs; the client reconnects. QUIC (RFC 9114 HTTP/3) is more sensitive: connection IDs and path validation assume a stable 4-tuple more than TCP's happy reconnect. CDNs engineer anycast-aware QUIC (connection ID routing, careful withdraw). Do not say "Anycast never moves."
Geo-DNS trap. The user is in Paris; their DNS resolver is a US 8.8.8.8 PoP; you steer them to Virginia. Anycast would have taken the TCP SYN to CDG. Complementary: Anycast the CDN VIP; use DNS for which VIP product (IPv4 vs IPv6, dual-stack, preview) and for origin failover when you are not on Anycast.
Sequence
- 1
Step1 User → Step2 DNS
Resolve cdn host
- 2
Step2 DNS → Step1 User
Same VIP worldwide (or geo answer)
- 3
Step1 User → Step3 Anycast POP
TCP or QUIC plus TLS ClientHello to VIP
- 4
Step3 Anycast POP → Step3 Anycast POP
Step5 Terminate TLS, HTTP/2 or HTTP/3
- 5
Step3 Anycast POP → Step1 User
Encrypted response
- 6
Step3 Anycast POP → Step4 Origin
Step6 TLS to origin (mTLS optional)
- 7
Step4 Origin → Step3 Anycast POP
Response
- 8
Step3 Anycast POP → Step1 User
Encrypted response
Lesson map
TLS Termination & Anycast Edge
Edge TLS plus Anycast cuts handshake RTT and shares one VIP worldwide. Trade-off: anycast can flap, keys live at the edge, and origin still needs a private path (mTLS).
Architecture. Architecture
Select a node to see why it exists, or an edge to see the protocol, direction, effect, and consequence.
Mermaid export
flowchart TB u["Step1 User"] d["Step2 DNS"] p["Step3 Anycast POP"] o["Step4 Origin"] u -->|Resolve cdn host| d d -->|Same VIP| u u -->|TCP or QUIC plus| p p -->|Encrypted| u p -->|Step6 TLS to| o o -->|Response| p
TLS offload vs end-to-end
Offload / termination at the edge: client ↔ POP is TLS. POP sees HTTP. POP ↔ origin should be TLS again (often with a different cert). This is two hops of encryption. The CDN is a trusted reverse proxy.
True end-to-end TLS (client encrypts to origin keys the CDN cannot decrypt) fights the point of a inspecting CDN. Tunneling CONNECT-style is not how HTML CDNs work.
Origin policy: never fall back to cleartext "because VPC." VPC is not encryption; it is a routing domain. Prefer private link or mTLS. Pin CA / ciphers if you must. Rotate origin certs with the same ACME automation you use at the edge.
When edge termination is the wrong product. If the threat model is "nobody but origin may see plaintext" (some healthcare, some payments, mutual-TLS APIs to partners), a inspecting CDN cannot sit in the middle. Options: skip the CDN for that hostname, use a tunnel that does not terminate HTTP, or a private/enterprise POP with contractual isolation — still not end-to-end to the browser. Public HTML sites almost always pick offload because WAF and cache require bytes.
Warm shield → origin TLS is why a cold miss is not 300 ms of handshake: the POP already has a session. That reuse is a latency side effect of hierarchy; the primary reason for a shield remains origin QPS.
Architecture
Anycast data plane
- 1
Same VIP announced at IAD / ORD / CDG
- nextBGP picks POP
- 2
BGP picks POP
- nextSick POP: withdraw prefix
- 3
Sick POP: withdraw prefix
Geo-DNS control plane
- 4
Resolver location / ECS
- nextDifferent A records
- 5
Different A records
- nextTTL holds a bad answer
- 6
TTL holds a bad answer
Resolver in Virginia, user in Paris: geo-DNS may pin IAD until TTL dies. Anycast would have taken the SYN to CDG. Use Anycast for the VIP users hit; use DNS for product selection and for origins that are not Anycast.
HTTP/2 vs HTTP/3
| HTTP/2 (TLS over TCP) | HTTP/3 (QUIC / RFC 9114) | |
|---|---|---|
| Multiplex | Many streams, one TCP connection | Many streams, one QUIC connection |
| Head-of-line | TCP HOL: one loss stalls all streams | Loss is per-stream; still has QUIC HOL for some frames |
| Handshake | TCP + TLS (1-RTT TLS 1.3 typical) | Combined crypto + transport; often faster on lossy links |
| Migration | New TCP 4-tuple = new connection | Connection IDs can migrate; Anycast still dangerous |
| Middleboxes | Widely understood | UDP 443 may be blocked; always keep H2 fallback |
At the POP, multiplexing is why one client connection fetches HTML + 40 assets without 40 handshakes. When sizing origin, remember the shield already coalesces — HTTP/2 to origin is connection reuse, not 40 WAN handshakes per page. See request collapsing for the miss storm HTTP/2 does not fix.
HOL, loss, and Anycast. On a 2% lossy mobile path, HTTP/2 over TCP stalls all streams on one retransmit. HTTP/3 recovers per-stream, which is why CDNs push it for last-mile. The cost is UDP 443 and Anycast: if BGP shifts the 4-tuple to another POP, QUIC must path-validate; a naive anycast withdraw looks like packet loss plus a new path. TCP usually RST + reconnect, which browsers already handle. Staff answer: enable HTTP/3 with HTTP/2 fallback; treat Anycast flap as a real QUIC bug class, not theoretical.
Session resumption. After the first POP handshake, session tickets (or TLS 1.3 PSKs) make the next navigation 0-RTT/1-RTT. Ticket keys are as sensitive as cert keys for that ticket lifetime. Rotate on a schedule; do not copy a static ticket key into a git repo so every POP "matches." 0-RTT early data is replayable — allow it for safe GET of cacheable HTML, not for checkout POST.
Certificates, tickets, stapling, keys
- ACME (Let's Encrypt) automates issuance. Monitor expiry; a missed renew is a site-wide outage the CDN will faithfully serve as TLS errors.
- SAN vs wildcard: exact names in SANs are tighter; wildcards are operationally easier and broader-blast on leak. Certificate Transparency logs both — watch CT for surprise issuances.
- Session tickets: the edge issues tickets so resumption skips a full handshake. Ticket keys must rotate; a stolen ticket key lets an attacker decrypt resumed sessions from that era.
- OCSP stapling: the POP staples OCSP so clients do not call the CA (privacy + extra RTT). If you disable stapling, mobile clients pay CA RTT or fail hard in some modes.
- Key custody: managed certs keep private keys in the vendor HSM/POP fleet. Uploading your own key to "every POP" expands the disclosure radius. Least POPs, HSM, or bring-your-own-key offerings when compliance cares.
- Policy: TLS 1.3 preferred; TLS 1.2 floor; disable 1.0/1.1. Client auth (mTLS from browsers) is rare at the CDN; that usually lives at the API gateway. mTLS from CDN to origin is the common staff ask.
SANs in practice. shop.cdn and www.shop.cdn and static.shop.cdn are three names. One cert can list them all in SANs, or *.shop.cdn covers the last two and not the apex. Apex + wildcard usually means two certs or a SAN that includes the apex. ACME HTTP-01 needs port 80 at the answering POP; DNS-01 is how you automate wildcards. CT monitoring is how you notice a cert you did not request.
Failover and health checks. Anycast withdraw is only as good as the health signal. If a POP is blackholing HTTP but still announcing BGP, users stick to a dead edge. Probe the data path (TLS + HTTP), not only the route. Combine with stale-if-error so other POPs can keep serving.
Deep dive · mTLS to origin and origin-IP bypass
Attack: attacker learns origin IP (history leak, DNS, mis-set Host) and pulls origin, skipping WAF, auth, and cache. Defense in layers: origin cert that requires client cert from the CDN, firewall allow-list of vendor egress (brittle as ranges change), or private connectivity. Rotate CDN client certs with automation. This is independent of Anycast. You want both: Anycast for users, locked origin for everyone else.
Playground: Anycast picker vs geo-DNS vs handshake budget
No sockets. POPs have a BGP distance and a geographic latitude. Geo-DNS uses resolver latitude, which can disagree with the user.
Press Run. Snippets must be self-contained — no network, files, or native modules.
Interview Q&A
Anycast vs geo-DNS?
Answer
Anycast: one IP, routing decides POP, failover by BGP withdraw, coarse topological steering, flap risk. Geo-DNS: different IPs per answer, finer policy, TTL and resolver location can mis-steer. Many CDNs Anycast the VIP and still use DNS for product selection. Do not treat them as synonyms.
Why terminate TLS at the edge?
Answer
Handshake RTT is local, so TTFB on a HIT is tens of milliseconds instead of hundreds. The POP can inspect HTTP for WAF, apply cache keys, and multiplex HTTP/2 or HTTP/3. Origin TLS stays warm on the shield path.
Is plaintext to origin OK inside a VPC?
Answer
No for sensitive data. VPC is not encryption. Re-encrypt POP/shield → origin. Prefer mTLS or private link so a leaked origin IP is not an open website. Cleartext origin is a finding, not an optimization.
QUIC / HTTP/3 plus Anycast?
Answer
HTTP/3 rides UDP. If BGP moves the flow to another POP mid-connection, QUIC path validation can fail harder than TCP reconnect. CDNs that ship HTTP/3 on Anycast engineer connection-ID routing and careful withdraw. Keep HTTP/2 fallback. Enable HTTP/3 because of lossy last miles, not because it is fashionable.
Why staple OCSP?
Answer
So the client does not call the CA on every new connection (extra RTT, privacy leak of which site they visit). The edge staples a fresh OCSP response. Failure to staple plus hard-fail clients equals outage.
When is mTLS to origin required?
Answer
When origin must authenticate the CDN (and only the CDN). Shared-secret headers are forgeable if origin is reachable. mTLS plus firewall/private link. Rotate certs with ACME-like automation. Browser mTLS is a different, rarer design.
Where do private keys live?
Answer
At every POP that terminates your hostname, unless you use a design that holds keys in HSMs and distributes brief session material. Managed certs reduce your handling; custom uploads expand blast radius. Ticket keys are keys too — rotate them.
Does HTTP/2 to origin replace collapsing?
Answer
No. Multiplexing reuses a connection; it still sends N GETs if N misses occur. Collapsing turns N misses for one key into one GET. You want multiplex and single-flight and a shield.
How do you fail a sick POP?
Answer
Health checks → withdraw Anycast announcement (or DNS fail away if that is your plane). Clients on existing TCP may RST; that is acceptable compared with serving errors. Hold stale-if-error long enough that surviving POPs still have a body.
Wildcard vs SAN vs ACME monitoring?
Answer
Wildcards cover *.shop with one cert and one leak blast. SANs list exact names. ACME must be monitored — expiry is a self-inflicted DDoS. Watch CT logs for issuances you did not request.
Pitfalls
| Pitfall | What actually happens |
|---|---|
| Uploading private keys to random shared hosting | Key disclosure; attacker impersonates you |
| TLS 1.0 / 1.1 left on | Compliance fail; old crypto |
| Assuming Anycast never moves | Mid-flow POP shift; QUIC more painful than TCP |
| Cert expiry without ACME alerts | Global TLS errors at the VIP |
| Cleartext origin "because VPC" | Bypass + disclosure on the origin path |
| Ignoring HTTP/2 multiplex when sizing | Over-count origin connections; under-count request QPS |
| HTTP/3 without H2 fallback | UDP-blocked clients cannot connect |
| 0-RTT on non-idempotent POST | Replay |
Pick origin RTT = 120 ms, POP RTT = 12 ms. Write TTFB for origin-only TLS 1.2, origin-only TLS 1.3, and edge HIT TLS 1.3. Then move the user to Paris with a Virginia DNS resolver and show geo-DNS vs Anycast POP choice. Circle the mTLS arrow to origin — that is the bypass defense.
Go Deeper
- Cloudflare — Anycast network
- RFC 9114 — HTTP/3
- Let's Encrypt — ACME
- CloudFront — Using HTTPS
- Talk — Anycast networking explained
Sibling pages: CDN hierarchy · Cache keys · SWR / stale-if-error · Purge and generation tokens · Request collapsing