The question this answers
What changes in my infrastructure when an edge network sits in front of it?
The application serves a JavaScript bundle, product images and an API from one hostname, to users on four continents. Static assets are identical for every user, they dominate bytes transferred, and users in Sydney currently wait for every one of them to cross an ocean.
A globally distributed cache in front of the origin: repeat requests for cacheable content are answered near the user and never reach your infrastructure, and the origin can be made unreachable except through the edge.
Two hops, and what each one is for
The topology is short. A user resolves the hostname to the nearest edge location. If the edge holds a fresh copy of the object, it answers directly and your infrastructure learns nothing about the request. If it does not, the edge fetches from the origin — object storage for static assets, a load balancer for dynamic responses — caches it according to the response headers, and serves it. Every subsequent request in that region is served locally.
The latency argument is the obvious one and it is mostly about round trips rather than bandwidth: a TLS handshake to an edge 20 ms away beats the same handshake to an origin 250 ms away, and a page that fetches thirty assets pays that difference thirty times over. The Networking domain covers why. What matters from the infrastructure side is the second and third effects.
The second is offload. A high cache-hit ratio means most requests never reach the origin, so the origin is sized for the misses rather than for the traffic. That changes autoscaling behaviour, changes the egress bill, and provides genuine protection during a traffic spike — a link that goes viral is absorbed by the edge instead of by your fleet. The third is origin protection: once everything arrives through the edge, the origin can be locked down so that only the edge may reach it, which converts a public bucket or a public load balancer into a private one.
What to cache, and the rule that prevents the incident
Cacheability is decided by the response, and the decision is entirely yours. Static assets with content-hashed filenames are the easy case: the filename changes whenever the content does, so they can be cached effectively forever and a deploy invalidates nothing — it simply publishes new names. This is the pattern worth designing toward, because it removes the invalidation problem instead of managing it.
The dangerous case is a per-user response cached as if it were public. A response containing one customer's data, served from an edge to the next visitor, is a data-exposure incident caused by a caching header. The rules that prevent it are mechanical: anything behind authentication is private, no-store unless you have explicitly reasoned otherwise, the cache key must include every input the response varies on, and cookies and authorization headers must be excluded from being cached, not merely forwarded.
Invalidation is the other operational reality. A purge is not instant and not free — providers rate-limit or charge for it, and it propagates across a global network over seconds to minutes. Designing so that purges are rare, by versioning URLs rather than overwriting them, is worth more than any purge tooling. See CDN Architecture in the Architecture domain for the strategy side.
| Content | Cache at the edge? | Key on | Why it goes wrong |
|---|---|---|---|
| Hashed static assets (app.9f3c.js) | Yes — effectively forever. | Path only. | Nothing. The name changes when the content does; this is the target design. |
| Unhashed static assets (logo.png) | Yes, with a short TTL. | Path only. | A deploy requires a purge, and the purge is neither instant nor free. |
| Public API responses (product catalogue) | Yes, seconds to minutes. | Path, query, Accept, Accept-Encoding. | A missing query parameter in the key serves the wrong page to everyone. |
| Personalized pages | No — private, no-store. | n/a. | One user's data served to the next visitor. This is the incident. |
| Authenticated API responses | No, unless deliberately keyed on identity. | n/a. | Authorization header not in the key means the cache ignores who is asking. |
| Large media and downloads | Yes, with range support. | Path. | Nothing — this is where the egress saving is largest. |
The bill, which usually goes down
A CDN is one of the few components in this domain that frequently *reduces* total spend rather than adding to it. The reason is that edge delivery is usually cheaper per gigabyte than origin egress, and every cache hit removes a gigabyte from the more expensive meter entirely. At a high hit ratio the origin serves a small fraction of the bytes, and the saving on origin egress commonly exceeds the CDN's own charges.
The compute saving is real too and less visible. Requests served at the edge do not reach the load balancer, do not occupy an application thread and do not count toward the metric your autoscaler watches — so the fleet is smaller. The offload also flattens spikes, which means less scaling churn and less over-provisioned headroom.
The line item that surprises people is invalidation, along with per-request charges in regions with different rates and the cost of edge functions if you run logic there. And the cost that is not money: an aggressively cached asset served with a wrong header is served wrongly everywhere at once, which is a much larger blast radius than a bad response from one origin. See Egress: Moving Data Costs Money, Not Just Storing It.
Bars are relative weights, not currency. Real rates depend on provider, region, commitment and volume.
Key points
- A CDN is three things at once: lower latency, origin offload, and an origin-protection boundary.
- The origin should be reachable only through the edge — a public bucket behind a CDN is a bypassable origin, not a protected one.
- Content-hashed filenames remove the invalidation problem entirely; purges are neither instant nor free.
- Caching an authenticated or personalized response at a shared edge is a data-exposure incident caused by a header.
- It usually lowers total cost, because edge delivery is cheaper per gigabyte and a hit removes the byte from the origin meter altogether.
The loop, answered
Every field is required, which is why no lesson here can recommend something without saying what it costs and what simpler thing to consider first.
- • DNS resolves the hostname to a nearby edge location, typically via anycast or a latency-aware answer.
- • The edge computes a cache key from the request — path, and whichever query parameters, headers and cookies you configured — and looks for a fresh object.
- • On a hit it responds locally; the origin never sees the request and no origin egress is billed.
- • On a miss it fetches from the origin over a connection the origin can restrict to the edge, then stores the response according to its cache-control headers.
- • Invalidation removes objects before their TTL expires, propagating across the edge network over seconds to minutes.
- • Own the cache key explicitly. Every input the response varies on must be in it, and nothing else should be.
- • Own the origin lock-down: an origin-access identity for storage, and an edge-only allow-list plus a shared secret header for a load-balancer origin.
- • Own the certificate for the edge hostname and its renewal, which is a separate certificate from the origin's.
- • Own the deploy sequence for assets: publish new hashed names first, switch references second, and never overwrite in place.
- • Own the hit-ratio metric per content type, because a single uncacheable response pattern can quietly collapse the offload.
- • A personalized response cached publicly and served to other users — the highest-severity failure in this lesson, and it is caused by one header.
- • A cache key missing a query parameter, so every variant of a page serves whichever version was cached first.
- • A stale asset after a deploy because the filename did not change and the purge did not propagate before users arrived.
- • A collapsed hit ratio after a header change, sending full traffic to an origin sized for misses — which then falls over.
- • An origin that was never locked down, letting attackers bypass the edge entirely and hit the origin address directly.
- • The edge absorbs traffic spikes for cacheable content, so origin capacity is sized for the miss rate rather than the request rate.
- • A cold cache after a purge or a new release produces a burst of origin requests — the CDN equivalent of a thundering herd.
- • Request collapsing at the edge, where supported, deduplicates simultaneous misses for the same object into one origin fetch.
- • Uncacheable traffic does not scale at the edge at all; it is proxied straight through, so an API-heavy workload gets latency benefits without offload.
- • The edge is the outermost trust boundary and the natural place for TLS, WAF rules and rate limiting.
- • Origin protection is the real infrastructure gain: with an origin-access identity or an edge-only allow-list, the origin stops being publicly reachable at all.
- • Cache poisoning and cross-user cache leakage are the specific risks, and both are cache-key problems rather than infrastructure problems.
- • Edge access logs are the complete record of public traffic, including the requests your origin never saw, and they belong in the same store as the rest of the audit trail.
- • Charges are data transfer out by region, requests, and invalidations, plus edge compute if used.
- • The offset is origin egress, which usually falls by more than the CDN charges add at a decent hit ratio.
- • Regional rate variation is substantial, so a globally distributed user base has a genuinely different cost profile from a single-region one.
- • Invalidation is the surprise line item, and a deploy pipeline that purges everything is the usual cause.
- • Cache hit ratio by content type — the single number that says whether the CDN is doing its job.
- • Origin request rate and origin egress bytes, which should be a small fraction of edge traffic and which reveal a collapsed ratio immediately.
- • Edge error rates split from origin error rates, so an edge problem is not diagnosed as an application problem.
- • The signal that lies: application-side latency and request counts. Both look excellent precisely because the edge is absorbing the traffic, and they stay excellent while edge users are being served stale or wrong content.
- • Object storage with a public read policy and sensible cache headers, for a small site with a regional audience — a CDN adds little when everyone is one hop away.
- • Cache headers alone, letting browser caches do the work, when repeat visits dominate and the audience is not globally spread.
- • A regional cache or reverse proxy in front of the origin, when the goal is offload rather than global proximity.
- • Nothing at all, for an internal tool or an API with no cacheable responses — a CDN in front of uncacheable traffic buys latency and adds a component.
- • Buys global latency and origin offload, usually for a net saving; costs a cache you must reason about on every response.
- • Buys a strong origin-protection boundary; costs the discipline to actually lock the origin down, which is a step teams skip.
- • Buys spike absorption; costs a blast radius where one wrong header is wrong in every region simultaneously.
What people believe, and what is true
A CDN is only for static files.
It also terminates TLS at the edge, absorbs spikes, protects the origin and can cache API responses that are genuinely public — while uncacheable traffic still benefits from edge-terminated connections.
Putting a CDN in front makes the origin secure.
Only if the origin is locked to the edge. A public bucket or a public load balancer behind a CDN can be addressed directly, bypassing every edge control you configured.
Purging is how you deploy new assets.
Purging is a fallback. Content-hashed filenames mean a deploy publishes new names and invalidates nothing, which is faster, cheaper and has no propagation window.