CDNs and Edge Networks

How caching, DNS steering, anycast, and edge compute bring content closer to users.

Est. 18–26 min Updated Suggest a fix

Prerequisites: Understand DNS resolution, HTTP responses, headers, TLS, and the role of an origin server.

Learning objectives: Trace a CDN cache hit and miss, design safe cache keys and freshness policy, explain invalidation and edge routing, and identify privacy and origin-protection risks.

Chapter 01

Why Place Content Near the User?

A learner in Vijayawada opens a course video hosted by one origin region thousands of kilometres away. Every byte crossing that distance adds propagation delay, and one origin must serve users in many locations. A content delivery network (CDN) places copies or delivery capacity at many points of presence (PoPs), so suitable requests can be answered closer to the learner while the origin remains the source of truth.

A CDN is a distributed system of edge servers, routing and cache-control logic, and connections back to origin services. It can accelerate static files, video segments, downloads, and sometimes dynamic requests. “Edge” means computation or delivery near a user or device; it is broader than caching. A nearby edge server can still miss its cache, so proximity alone does not guarantee a fast response.

Browser / app
    │ DNS or anycast routing selects an edge PoP
    ▼
Edge cache ── cache hit ──► response to user
    │ cache miss / revalidation
    ▼
Origin shield (optional shared cache)
    ▼
Origin application and object storage

Benefits can include lower latency, fewer repeated origin requests, better absorption of traffic spikes, and a distributed place to apply TLS, request filtering, and rate controls. A CDN is not a substitute for application security, durable origin capacity, or a tested multi-region recovery plan.


Chapter 02

The Request: Edge Selection, Hit, and Miss

Providers may direct users using DNS-based steering, anycast IP announcements, or a combination. With DNS steering, a resolver receives an answer selected using factors such as location and health; cached DNS answers can mean the change is not immediate for every client. With anycast, the same service address is announced from multiple locations and network routing usually carries a client to a nearby reachable PoP. “Nearby” is a routing outcome, not always the shortest geographic path.

On arrival, the edge builds a cache key from configured request properties—commonly host, path, and selected query parameters or headers. If a fresh object matches, it is a hit. If not, the edge fetches from origin, may store the response if policy allows, then returns it. Revalidation can ask the origin whether a stored representation is still valid, using validators such as ETag or Last-Modified.

What affects a cache key?

  • Host and normalized path determine which resource is requested.
  • Query parameters may be meaningful, ignorable, or require allow-listing.
  • Headers in Vary can separate representations such as compressed and uncompressed responses.
  • Cookies and authorization data usually signal personalized or private content and need careful handling.
Common mistake: An incomplete cache key can serve the wrong version to users—for example, mixing languages or device variants. An overly broad key can leak one user's personalized response to another. Treat cache-key design as correctness and privacy engineering, not just a speed setting.

Chapter 03

HTTP Caching and Freshness

HTTP response headers describe whether and for how long a response can be reused. Cache-Control: max-age communicates freshness to caches; s-maxage applies to shared caches; private limits storage to a private cache; no-store says not to store the response. ETag supports conditional revalidation. A CDN may also have an explicit edge policy, so confirm how provider rules interact with origin headers.

# Versioned public asset: safe to cache for a long time
HTTP/1.1 200 OK
Content-Type: text/css
Cache-Control: public, max-age=31536000, immutable
ETag: "asset-build-8f31"

# Personalized account response: do not store in shared caches
HTTP/1.1 200 OK
Content-Type: application/json
Cache-Control: private, no-store

Long-lived caching is safest when the URL changes whenever the content changes, such as a build-hashed filename. For a stable URL whose content changes, use a shorter freshness window or revalidation. A stale-while-revalidate policy can let an edge serve a still-useful stale object while it refreshes, but only where temporary staleness is acceptable.

# Inspect response cache headers without downloading the body
curl -sS -I https://static.example.test/assets/app.8f31.css

# A diagnostic response may expose provider-specific cache status
# Look for a documented cache-status header: HIT, MISS, or BYPASS
# The exact header name depends on the CDN.
Cache caution: Do not copy the numeric max-age from a sample into production without a content-update plan. A long TTL is a promise that a stale copy may remain visible until it expires or is explicitly invalidated.

Chapter 04

Cacheability, Privacy, and Origin Protection

Static files are natural cache candidates. Dynamic pages can be cacheable too if every user receives the same representation for a given key and the response policy says so. Account pages, payment status, one-time tokens, private API responses, and pages that embed session-specific data should not be shared-cacheable by accident. Review Set-Cookie, Authorization, and cache-control behavior together.

A CDN can reduce origin load only when traffic actually hits cache or is otherwise absorbed at the edge. For a cache miss storm—such as a new release, a purge, or a popular object expiring—an origin shield can consolidate fetches from edge locations. Request coalescing, rate limits, and origin capacity plans further reduce stampedes. These protections must preserve correctness under concurrent updates.

# A safe application decision, shown as pseudocode
if response_is_public_and_identical_for_all_users:
    set_header("Cache-Control", "public, max-age=300, s-maxage=1800")
else:
    set_header("Cache-Control", "private, no-store")

# Never rely on a CDN default to protect user-specific data.

Keep origin access constrained where possible: allow only expected CDN egress ranges or use an authenticated origin connection supported by the provider. Otherwise, an attacker may bypass edge rate controls and hit the origin directly. Protect administrative endpoints separately and avoid treating IP allow-lists as user authentication.


Chapter 05

Invalidation and Content Updates

Cache invalidation means making stored objects unavailable before their natural expiry. A broad purge is simple but may create a wave of origin misses. Purging by URL or tag is more targeted when the CDN and application support it. Another approach is versioned URLs: publish a new immutable filename and update the HTML that references it. This avoids waiting for an old file to expire and reduces the need for global purge operations.

A release sequence that limits surprises

  1. Upload new versioned assets and verify them from the origin.
  2. Publish HTML or manifests that reference the new asset names.
  3. Warm critical paths if the release is expected to create a miss spike.
  4. Observe cache status, origin request volume, errors, and regional latency.
  5. Retain old assets long enough for cached HTML and clients still to reference them.

Purge APIs are provider-specific, and a purge request may be asynchronous. Do not assume that an accepted purge has already propagated everywhere. Confirm the semantics and test the user-visible result from representative regions.


Chapter 06

Edge Compute and Anycast Trade-Offs

Edge functions can perform lightweight work near users: redirects, header normalization, A/B assignment, authentication checks, or routing to a nearby service. They run in a constrained environment and may have different limits, runtime APIs, and state models from a full application server. Keep authoritative writes and complex business rules in systems designed to own them unless the edge platform explicitly supports the required guarantees.

Anycast can improve reachability and distribute traffic, but a route change or PoP failure can move a client to a different location. Do not assume edge-local memory is durable or shared across locations. If an edge function needs state, use a store with documented consistency and availability characteristics, and decide what happens when it is unavailable.

# Edge decision flow (provider-neutral)
1. Validate the incoming host and path.
2. Reject malformed or disallowed requests early.
3. Redirect a canonical URL if required.
4. Serve a public cache hit when the cache key is safe.
5. Forward a miss to the configured origin.
6. Emit a request ID and timing metadata; never log secrets.
Cache caution: “At the edge” does not automatically mean private, compliant, or secure. Consider where logs and data are processed, what personal data is visible to edge code, and the geographic and contractual requirements that apply to your application.

Chapter 07

Measure the User Experience, Not Just Hit Rate

A high cache-hit ratio can coexist with slow pages if the hit objects are large, the user misses the nearest PoP, or the application has uncached API calls. Track latency percentiles by region and route, edge and origin error rates, bytes served, cache hit/miss/bypass, origin fetches, purge events, and TLS failures. Include the cache status and request ID in diagnostics without exposing tokens or personal data.

# Compare response metadata from two locations you control
curl -sS -o /dev/null -w 'status=%{http_code} ttfb=%{time_starttransfer}s total=%{time_total}s
'   https://www.example.test/catalog

# Repeat from a second approved region or monitoring probe.
# Compare like-for-like URLs and inspect documented CDN headers.

When an incident occurs, distinguish edge failure from origin failure: compare a normal user request with a controlled origin check, inspect DNS and TLS, verify the cache status, and check whether recent changes altered routing or cache keys. Bypass tests should be limited to infrastructure you own or are authorised to operate.


Chapter 08

Mistakes to Avoid and Practice

  • Caching every 200 response: status code alone does not establish that a response is safe to share.
  • Ignoring query strings: parameters may select different products, pages, or language variants.
  • Purging everything on every deploy: broad purges can overwhelm an origin with simultaneous misses.
  • Assuming the nearest PoP is always used: routing policy, resolver location, and reachability affect selection.
  • Measuring only hit ratio: pair it with regional latency, origin load, and error rate.

Practice

  1. Choose cache headers for a build-hashed JavaScript file and explain why it can have a long TTL.
  2. Decide whether an order-status API response may be cached by a shared CDN. State the privacy assumptions.
  3. Draw a request path for a cache hit and a cache miss, including the origin shield if present.
  4. Explain one benefit and one risk of anycast-based edge selection.
  5. Plan a release that updates a frequently used asset without a global purge.

🎯 Key Takeaways

  • ✓A CDN combines distributed edge infrastructure with routing and cache policy; edge delivery is more than a collection of copies.
  • ✓A cache key must distinguish every representation that matters while excluding private user-specific data.
  • ✓Use explicit HTTP cache directives, validators, and versioned URLs to manage freshness deliberately.
  • ✓Origin shields and request coalescing can protect the origin during miss spikes, but do not replace capacity planning.
  • ✓Anycast and DNS steering have different routing and convergence behavior; neither guarantees the geographically closest edge.
  • ✓Measure regional latency, cache status, origin load, errors, and privacy—not only hit ratio.

HELP US IMPROVE

How was this lesson?

Your note is shared with the Chaduvuko team for review. Please don’t include personal or sensitive information.

Choose your feedback

Spotted a mistake or something unclear? Suggest a fix on GitHub or email us. Select the text first and it is quoted for you.

Share

Discussion

0

Have a better approach? Found something outdated? Share it — your knowledge helps everyone learning here.

Continue with GitHub
Loading...