Skip to content

Core system concepts · Concept lesson

CDN delivery

Deliver cacheable content from edge locations while controlling cache keys, freshness, origin protection, and user-specific data exposure.

Written for readers who already know the basics. If the words here are new to you, read The request lifecycle and Capacity estimation first.

Original educational architecture · Version 2026-11-12.1 · Examples use stated hypothetical assumptions, not a company's actual design.

What you will be able to explain

  • Explain how edge caching changes content delivery and origin load.
  • Design cacheability and invalidation rules for public and personalized content.
  • Evaluate cache-key correctness, cache misses, and origin protection.

How CDN delivery works

A content delivery network places edge points of presence closer in network distance to users. On a cache hit, an edge returns a stored response without contacting the origin; on a miss, it fetches the response, applies cache policy, and may retain it for later requests. This can reduce transfer latency, origin load, and repeated delivery of static assets. It does not make the origin disappear: dynamic or uncached requests still travel there, and invalidation or cache failure can create sudden origin demand. The response's cache directives, CDN configuration, and cache key determine whether a result is reusable. The key may include host, path, selected query parameters, and selected headers; including too little can serve the wrong variant, while including too much fragments the cache. Personalized responses need careful private or no-store treatment unless a verified safe partitioning scheme exists. CDN design is both a performance policy and a privacy boundary.

Edge delivery and origin fallback
1. User

Requests a representation from the site.

2. CDN edge

Evaluates the cache key and freshness policy.

3. Origin

Serves authoritative content on an edge miss.

4. Delivered response

Must match the caller's locale and privacy scope.

5. Cache policy

Controls allowed storage, variation, and expiry.

  1. User → CDN edge: content request
  2. CDN edge → Delivered response: cache hit
  3. CDN edge → Origin: cache miss
  4. Origin → CDN edge: fetch and optionally cache
  5. Cache policy → CDN edge: key and freshness rules
  6. Delivered response → User: content delivery

Worked example: static asset delivery

A cache key is a security decision as well as a performance decision. Imagine /account displays a user's email and plan, but the edge key contains only the URL path while the origin varies the response by authenticated cookie. If a shared edge caches the first response as public, a later user's request can receive the earlier user's representation. Do not rely on an assumption that cookies automatically make a CDN response private: inspect the effective cache policy and test two distinct authenticated users at the edge. For personalized endpoints, prefer private or no-store directives unless a reviewed design safely includes every authorization-relevant dimension and prevents direct-origin bypass. A high-cardinality user ID in the key can also create many sensitive retained objects and complicate deletion; keying is not a replacement for authorization. Public localized pages can instead use a normalized locale in the URL or cache key, with a bounded set of supported variants. Test query-string normalization, headers, cookies, and error responses for both cache poisoning and cross-user reuse. If a configuration mistake is deployed, purge the affected entries, preserve the incident evidence safely, rotate exposed credentials if any were present, and review whether origin logs can identify the served variants.

Assume a 300 KiB versioned JavaScript asset is requested 20,000 times per hour from users across several regions. Without edge caching, the origin may serve about 20,000 × 300 KiB = 6,000,000 KiB, roughly 5.72 GiB per hour in binary units, ignoring protocol overhead and compression. If edge hit ratio reaches 95%, origin transfers about 5% of that, or roughly 293 MiB per hour. This is an estimate; actual bytes depend on compression, range requests, revalidation, and cache fragmentation. Use a content-hashed filename such as app.abc123.js and a long immutable freshness lifetime because a new release has a new URL. Keep the HTML document on a shorter freshness policy so clients discover the new asset. If the asset changes without its versioned URL changing, users may retain old code until expiry or purge. Test the actual edge response headers and cache key, not merely the origin configuration.

Delivery alternatives

A CDN is well suited to public static assets, downloadable content, and responses that can be safely reused under a defined key. Direct origin delivery is simpler for low-volume internal systems or highly personalized responses where edge policy adds little. Browser caching can avoid a network round trip for repeat visits, while an edge cache benefits many users across locations. Dynamic acceleration can optimize transport without storing content, but its value depends on route and provider behavior. Object storage paired with an edge distribution often separates durable asset storage from delivery. Peer-to-peer delivery may help very large public files but introduces availability and trust considerations. Choose by measuring geography, payload size, repeatability, and origin load. A CDN cannot repair a slow origin on cache misses or make a non-cacheable API globally consistent. It may add a new configuration layer that must be tested with the application.

Failure and recovery

A cache miss during a regional edge issue sends more requests to the origin; if the origin was sized assuming a high hit ratio, a widespread cold cache can cause an outage. Use origin shielding, request collapsing, rate limits, and capacity headroom where supported. Stale-if-error behavior can preserve delivery for content that remains safe to serve, but it must not expose revoked access or stale critical decisions. Purges may be delayed or fail, and a broad purge can remove useful entries everywhere at once. Versioned asset URLs reduce reliance on emergency invalidation. If content is private, cache-key mistakes involving authorization or cookies can leak one user's response to another. Treat cache policy changes as deployable code: test headers, vary behavior, and purge scope. During recovery, confirm the origin is healthy before gradually restoring miss traffic. Log safe request identifiers and edge cache status without including credentials.

When not to cache at the edge

Do not publicly cache a response containing user-specific fields unless the policy and key guarantee isolation and the response is safe to reuse. If a permission revocation must apply immediately, a long edge TTL can be unacceptable. Do not cache responses whose content varies on an unmodeled header, query parameter, locale, or cookie. Avoid putting a CDN in front of tiny low-volume traffic when configuration and operational cost exceed performance gains. A CDN is not a substitute for origin authorization: callers can sometimes reach an origin directly unless access is restricted. Avoid cache-busting by adding arbitrary unique query strings, which defeats reuse and can increase origin load. For rapidly changing information, choose a freshness or revalidation strategy that matches its meaning, rather than assuming the edge always has the newest value.

Senior followups

Ask how the CDN cache key is constructed and which headers or query parameters are normalized. Can an attacker vary a harmless parameter to force cache misses or poison a shared entry? Which response directives does the edge honor, and where does configuration override them? How are origin access controls enforced so traffic cannot bypass the edge? What is the expected cache-hit ratio by content class, and how much origin capacity is needed during a cold start? Can a release use content-hashed assets and a short-lived entry document to avoid broad purges? Does the CDN store personally identifiable or regulated data, and how do deletion and retention policies apply? Evaluate regional failure, stale response, TLS, logging, and purge authorization. Senior review tests the effective deployed policy with real request variants and verifies both correct reuse and correct separation.

Operational practice

Inspect response headers from multiple edges and verify cache status, age, freshness, and variation behavior. Track edge hit ratio by content type, origin requests, origin transfer, latency, and error rate. Use synthetic requests with distinct users and locales to test that personalized content is never cross-served. During deployment, publish versioned assets first and HTML references second; retain old assets long enough for clients with cached pages. Restrict purge permissions and audit actions. Run a controlled cold-cache or origin-shield test to verify capacity limits before a large release. If an origin outage occurs, decide in advance which public assets can be served stale and which dynamic responses must fail closed. Keep origin access restricted to the CDN where feasible, while maintaining a secure administrative path. The delivery runbook should include cache-key diagnosis, purge scope, and safe rollback.

Terms in plain language

CDN
A distributed network of edge servers that delivers content closer to users and can cache eligible responses.
Origin
The authoritative server or storage location from which a CDN retrieves content.
Cache key
The set of request properties used to identify a stored response as reusable.
Purge
An operation that removes or invalidates cached content before its ordinary freshness expiry.

Preparing practice controls…

Check your understanding

These checks explain concepts. They do not measure architecture seniority or update readiness.

1. Why is a content-hashed filename useful for static CDN assets?
2. What is the primary risk of omitting a content-changing dimension from a CDN cache key?

Design independently

A site serves public static assets, localized product pages, and a personalized account endpoint through a CDN. Propose cache policies and a release strategy, and explain how to test for privacy and origin-load failures.

Hints, not a solution
  • Different content classes need different freshness and reuse rules.
  • A localization dimension may belong in the cache key.
  • Test cold-cache behavior as well as the normal high-hit case.

0 / 20,000 characters · Not saved

Your learning notes

Sign in to save

Marking a lesson read and reviewing an exercise are separate actions. Neither implies mastery. Saved work is account-owned; saves are explicit and do not queue offline.

References and boundaries

Primary documentation supports the mechanisms described. It does not certify these hypothetical architectures, prices or sizing assumptions. Review platform-specific behavior before implementation.

Cloudflare Documentation: Cache concepts

Primary CDN vendor guidance on edge caching, keys, and cache behavior.

Amazon CloudFront Developer Guide: Cache key

Primary vendor documentation on cache key composition and variation.

Back to curriculum