A conference publishes a public schedule. People open it from phones across several regions, and most arrive when registration opens. The schedule should load quickly everywhere. Registered attendees can also see their own ticket, which must stay private. If a service behind the website stops answering, what will attendees see? The answer depends on where the request stops, which connections already exist, and what each cache is allowed to serve.

By the end of this lesson, you can trace a cold and warm HTTPS request, distinguish DNS expiry from HTTP freshness, decide what an edge may share, estimate latency and origin load, and isolate common failures by hop. You should be comfortable with HTTP methods, status codes, and resource boundaries from API and Data Model Design.

DNS turns a name into a destination#

For https://events.example.com/schedule, the host is events.example.com, the default HTTPS port is 443, and the path is /schedule. DNS resolves the host. The path and HTTP headers arrive later, so DNS cannot send schedule requests to one origin and account requests to another based on their path.

The browser or operating system may already have an address. Otherwise a stub resolver typically sends the question to a recursive resolver, which can answer from its cache or follow referrals. On a fully cold walk, the resolver starts with known root-server addresses. The root points to servers for the top-level domain, such as .com. Those servers refer it to the authoritative servers for the delegated domain. The authoritative server answers for its zone. Cached referrals can shorten later walks. The browser typically receives the result without issuing each iterative query itself.

An A record carries an IPv4 address, and an AAAA record carries an IPv6 address. A CNAME gives a canonical name for an alias. If the destination address is unavailable in the answer or cache, the resolver must continue resolving that name. At a CDN-enabled hostname, the returned address often belongs to the edge network. Depending on the provider, DNS can influence the destination or network routing can select among sites advertising a shared address.

Follow a DNS cutover by hand

A resolver caches the old edge address at second 0 with a time to live (TTL) of 60 seconds. At second 30 the authority publishes a new address with a TTL of 15 seconds. Under ordinary TTL caching, the first resolver can keep answering with the old address until second 60. A resolver that queries the authority for the first time at second 35 can already see the new address. An open connection may also outlive the DNS record that helped create it.

For a planned cutover, lower the TTL ahead of time and give previously cached longer TTLs time to expire. Keep the old destination working through the overlap and watch traffic reach the new destination before retiring the old one. DNS changes take effect at different times for different clients.

A negative DNS result can also be cached. NXDOMAIN indicates that the queried name does not exist. A successful DNS response with no data for the requested type can describe a name that exists but has no record of that type. A resolver timeout or SERVFAIL calls for a separate investigation. None of these is an HTTP 404, which is a response from an HTTP participant after a request reaches it.

Transport delivers bytes. TLS authenticates and protects the connection.#

IP carries packets toward an address. Packets may be lost, duplicated, delayed, or reordered. TCP provides applications with an ordered byte stream and uses retransmission to recover from loss. A new TCP connection normally starts with a three-way handshake. A transport acknowledgment confirms reception of bytes by the peer’s transport stack. For the ticket purchase workflow, application acceptance or durable state still requires an application-level signal.

With HTTPS over TCP, TLS negotiates shared secrets, authenticates the server in the usual certificate-based setup, and protects application data against tampering and disclosure in transit. The client verifies the certificate chain and checks that the certificate covers the requested service name. The handshake can carry the server name through Server Name Indication (SNI) so a shared endpoint can select the appropriate TLS configuration. Application-Layer Protocol Negotiation (ALPN) selects an application protocol supported by both endpoints. Reusing an open connection avoids repeating its setup. TLS session resumption can also reduce the work of opening a later connection. Early data has replay implications, so a purchase must follow the application’s replay-safety requirements.

HTTP versionTypical secure transportWhat sharing a connection means
HTTP/1.1TCP and TLSPersistent connections allow reuse. Responses to pipelined requests are ordered.
HTTP/2TCP and TLSHTTP streams multiplex over one connection. Loss can delay all streams waiting on the underlying ordered TCP bytes.
HTTP/3QUIC over UDP with integrated TLS 1.3Independent ordered QUIC streams limit transport-level blocking across streams. They still share network capacity and congestion control.

The request still has an HTTP method, target, fields, and possibly content across all three versions. A browser can speak HTTP/3 to the edge while the edge speaks HTTP/2 or HTTP/1.1 upstream. When QUIC is unavailable, a client that supports other advertised options can use a TCP-based HTTP version.

Reverse proxies create separate hops#

A forward proxy acts on behalf of its clients. A reverse proxy presents the service endpoint to callers and forwards requests toward backends. A reverse proxy may terminate TLS, route by hostname or path, and distribute connections or requests. An API gateway applies API-facing policies such as token verification, quotas, and routing. A CDN operates distributed edge sites and can serve eligible responses from a shared cache. One deployment may combine these roles or place them on separate hops.

Before adding any of them, draw the browser reaching the conference origin directly. As geographically distant audiences grow, place the CDN in front of the origin and cache the public schedule there. Send account traffic through to an API gateway or origin. In this arrangement there are two security boundaries. A browser verifies the edge certificate for the public hostname. For upstream traffic, configure TLS and certificate verification on the edge-to-origin connection as well. Connect origin access to the intended edge or gateway identity, and accept forwarded client identity only from configured trusted intermediaries. Application authorization still belongs to the service that owns ticket access.

Architecture canvasAn HTTPS request at the CDN edgeAfter DNS tells the browser where to connect, the edge serves a fresh public schedule from its cache or uses a separate upstream connection to reach the origin.
An HTTPS request at the CDN edgeAfter DNS tells the browser where to connect, the edge serves a fresh public schedule from its cache or uses a separate upstream connection to reach the origin.HTTPSfresh copyupstream HTTPSBrowserCDN edgeEnds viewer TLSCache hitFresh public copyOriginOwns the schedule
Diagram key and text version
  • Entry
  • Process
  • Outcome
  1. Browser → CDN edge: HTTPS
  2. CDN edge → Cache hit: fresh copy
  3. CDN edge → Origin: upstream HTTPS

The diagram follows the request decision. On a fresh hit the edge responds directly. On an eligible miss or stale entry the edge contacts the origin and may store or refresh its response. A private route skips shared reuse and goes upstream.

An edge cache needs an identity and a lifetime#

The cache key answers “which request can reuse this response?” For a GET, start with the requested URI and identify everything that changes the representation. The conference schedule varies by language. A response with Vary: Accept-Language tells an HTTP cache to account for that request field when matching stored responses. In a CDN policy, verify how variants are keyed and forwarded. An explicit language path such as /fr/schedule is another way to make the variant part of the URL. Only discard a query parameter when you have established it cannot change the response or its access rules. Extra variation lowers reuse and increases origin load.

The cache lifetime answers “when can we reuse this response without checking with the origin?” An entry is fresh when its current age is less than its freshness lifetime. HTTP age reflects time since the response was generated or successfully validated, including time already spent in upstream caches. A downstream cache must account for that existing age. Under the simplified assumption that a response arrived with age zero, a lifetime of 30 seconds means a fresh hit at second 29 and a stale entry at second 30.

Response directiveWhat it means for the schedule or ticket
max-age=30A response becomes stale once its current age reaches 30 seconds.
s-maxage=120Sets an overriding freshness lifetime for shared caches, which must validate before reusing a stale response under this directive.
no-cacheThe response can be stored when otherwise permitted. Reuse requires successful validation.
privateAn unqualified directive prevents shared caches from storing the response. A private cache may store it if other rules allow.
no-storePrevents compliant caches from storing the response. Use this where the user's ticket must not remain in a cache.

Cookie authentication still needs a route-level sharing policy. Configure private routes to bypass shared lookup and storage and have the origin send the appropriate cache directives. Before rollout, verify the edge's effective policy with two distinct test accounts and inspect cache-status headers. For the public schedule, make language variation explicit and track a meaningful hit ratio. A high hit ratio across the entire site can hide both a poorly cached schedule and a misconfigured private route.

Revalidate a stale copy

The origin associates the schedule with an entity tag such as ETag: "schedule-v7". When the edge has a stale copy, it may ask with If-None-Match: "schedule-v7". If the selected representation is unchanged, the origin can answer 304 Not Modified without sending a replacement body. The cache updates relevant metadata and can serve its stored body to a caller asking for the whole representation. If the schedule changed, the origin sends a new 200 OK with the new body and validator.

A purge can evict edge copies before freshness runs out. Treat a purge as an edge operation with a propagation window, and remember that a browser may still hold its own fresh copy. Use content-versioned URLs for immutable assets. For the mutable schedule, choose a freshness window consistent with the maximum acceptable delay for updates. If the product permits it, a bounded stale-if-error extension can let a supported cache return the last public schedule after a qualifying upstream error. Test your provider and avoid using stale fallback for information that must be current.

Calculate the latency and load for the schedule#

Consider a single cold browser request over TCP and a full TLS 1.3 handshake, with setup phases serialized and no retransmissions. Let D=20 ms be DNS lookup time, R=40 ms the browser-to-edge round-trip time (RTT), and E=5 ms the edge's local lookup and response preparation time. An RTT is the elapsed time for a message to travel out and a reply to travel back. Ignore body transfer because we are calculating time to first response byte.

The browser spends about one RTT establishing TCP, one RTT completing the TLS setup needed to send the request, and one RTT on the HTTP request and first response bytes. The edge lookup occurs after the request arrives. The cold edge hit costs approximately

Cold edge hit = D + 3R + E = 20 + 3(40) + 5 = 145 ms.

For a cold viewer that encounters an edge miss, assume the upstream connection already exists, its request round trip is U=70 ms, and the origin spends P=25 ms generating its first byte. That adds 95 ms, so 145+70+25=240 ms. An open viewer connection and no DNS lookup lower those estimates to 45 ms and 140 ms. Treat these as request-path estimates, with measured connection reuse, network behavior, and queueing determining production results. The p95 of the whole route should be measured end to end, since the slowest phases need not occur on the same request.

Now suppose the edge receives 2,000 schedule requests per second and serves 90% without contacting the origin. At most one origin request per remaining viewer request gives 2{,}000(1-0.9)=200 requests per second, ignoring background work and retries. Revalidations that receive a 304 still count as origin requests. Immediately after a broad purge, that estimate can rise toward 2,000 requests per second. A CDN that coalesces concurrent requests for the same representation may reduce the burst. Distinct keys, multiple edge locations, and low reuse limit how much it can help. Size the origin against the measured miss-path burst as well as steady-state demand.

Decide what happens when the origin stalls#

Architecture canvasAn edge handles an upstream timeoutWhen the edge times out waiting for the origin, it serves a stored stale schedule only if policy permits that copy. Otherwise it reports the gateway timeout.
An edge handles an upstream timeoutWhen the edge times out waiting for the origin, it serves a stored stale schedule only if policy permits that copy. Otherwise it reports the gateway timeout.deadline passedeligible copyno eligible copyOrigin timeoutCheck stale policyLast public copyBounded stale age504 to viewer
Diagram key and text version
  • Entry
  • Process
  • Outcome
  1. Origin timeout → Check stale policy: deadline passed
  2. Check stale policy → Last public copy: eligible copy
  3. Check stale policy → 504 to viewer: no eligible copy

Cached schedules can be fresh at one site, stale but eligible at another, and absent at a third. The same outage can therefore produce fast successes, slow stale responses, and errors in different regions. An expired DNS record for the public hostname is a different failure: the browser may be unable to reach the edge in the first place. A healthy edge cache cannot help clients whose requests never reach it.

A 504 indicates that a gateway failed to get a timely upstream response. A 502 indicates an invalid upstream response under HTTP semantics. A 503 indicates that the responding service is currently unable to handle the request, for instance during overload or maintenance. Provider-specific mappings can vary. For a timed-out ticket write, the caller has not learned whether the upstream accepted it. Preserve the retry identity from the previous lesson and check the operation's state before assuming failure.

Set a viewer deadline and budget upstream connection, TLS, and response time within it. Decide which layer is responsible for retries, and grant retries only when the operation is safe to replay and enough time remains. If a viewer and an edge each allow three attempts, one action can drive nine upstream attempts. Capped backoff and jitter spread retries out, while an attempt budget limits amplification.

Debug in the same order you designed the path#

User-visible symptomEvidence to collectLikely boundary
Hostname fails to resolveCompare recursive and authoritative answers, record types, and remaining TTLsDNS and delegation
Address resolves but HTTPS failsIdentify connection stage, protocol, hostname, and certificate verification resultRouting, transport, or TLS
Wrong language or unexpectedly old scheduleInspect URL, variant fields, effective edge key, age, validators, and cache statusRepresentation or freshness policy
One region intermittently returns a gateway errorCompare edge location, upstream connection and response timings, origin traces, and hit ratesEdge-to-origin path or a regional dependency
Latency rises sharply after a purgeMeasure origin attempt rate, cache misses, revalidation traffic, and origin saturationCold cache and constrained miss path

Start with the client-visible failure. Probe from affected and healthy regions and separate failures before HTTP from failures with an HTTP response. Split edge timings into cache lookup, connection setup, and upstream wait where telemetry allows. Compare success and error latency separately and correlate edge logs with origin traces. At the origin, check traffic, errors, latency, and saturation. A flat origin traffic graph during a DNS outage is possible because the failed users never reached the service. Use external availability probes alongside internal instrumentation.

In an interview, take one critical URL and trace four cases: cold viewer, warm viewer, edge miss, and origin timeout. For each case name the TLS boundary and explain who answers and how you know. Then budget the latency and origin load, show the private route's authorization and cache policy, and answer what changes under a regional or global failure. This extends the previous lesson's contract into an observable request path.

Run the Python lab#

Download the lab and execute python3 05-networking-http-dns-cdn.py. It uses the standard library on Python 3.10 or newer. The deterministic clock lets you inspect resolver expiry, language variants, conditional revalidation, bypass, upstream failure, and the exact end of stale eligibility. The simulation models one hostname and origin, GET requests, normalized languages, and a 304 that leaves cache policy unchanged. It assumes a single cache where upstream response age and transfer time are zero. It uses a simulated timeout and makes no network calls.

Its fresh-hit condition is now - stored_at < max_age. On a stale lookup, the origin simulator compares the stored ETag with the selected upstream representation. A match refreshes the existing entry using the clock. A changed tag replaces the response when its policy allows sharing. A timeout tests the age of the existing public copy against the stale window. A cold cache raises the timeout because it has no representation to reuse.

Try it yourself

Diagnose a failed cutover

The first resolver cached address A at second 20 with TTL 120 seconds. At second 40 the authority publishes address B with TTL 30 seconds. A second resolver first asks at second 50. What answers can the two resolvers give at second 60, and what must happen before all traffic leaves A?

Reveal solution

The first resolver can answer A through second 139, and the second can answer B at second 60. Preserve service at A until cached answers have aged out and old connections have drained. Verify that traffic actually reaches B and subsides at A before decommissioning it.

Try it yourself

Decide whether stale content is still eligible

An edge cached an English schedule at second 100 with max-age=30, stale-if-error=45 and initial age zero. Assume the configuration honors both directives. The origin times out at seconds 175 and 176. What can the edge return at each time? What happens if a second edge never cached the English schedule?

Reveal solution

The schedule becomes stale at second 130. At second 175 it is exactly 45 seconds stale, so the first edge can serve it under the stated policy. At second 176 the permitted age has passed. The second edge will report its upstream failure at either time because it has no matching stored representation.

What can a successful DNS lookup prove about HTTPS to the edge?

The cache stores a stale schedule and receives a 304 after sending an ETag to the origin. What happens?

Why might users see different results during an origin outage even when they all reach the CDN?

Memory chart#

DNS                     name → address, cached by record lifetime
Transport and TLS       connect → authenticate → protect a specific hop
HTTP                    method + target + headers → representation or error
Edge                    eligible key + fresh entry → serve
                        stale entry → validate, or use permitted fallback
                        private route or miss → upstream work
Troubleshoot            browser → resolver → edge → origin

The next lesson follows an upstream request into a pool of replicas and examines load balancing, health checks, and horizontal scaling.

References#