Free tech learning for everyone, from basics to pro

Network FundamentalsNetworking SecurityBeginner

Content delivery networks (CDNs): how caching at the edge speeds up websites and absorbs attacks

In short: A CDN keeps copies of website content on servers in many locations around the world. Users are routed to the nearest edge server, which answers from its cache when it can and only fetches from the origin server when it must. This makes sites faster, reduces load on the origin and spreads attacks across a huge network.

The problem CDNs solve

If a website's only server is in London, a visitor in Sydney waits for every image and script to travel across the world, around 250 ms or more each round trip. A sudden rush of visitors, or a DDoS attack, can also overwhelm that one server. A content delivery network places servers (called edge or PoP servers) in hundreds of cities, close to users.

Loading a page through a CDNUserrequests imageDNS / anycastroutes tonearest edgeEdge servercache hit?serve itOriginonly on cachemissCached atedgefor the nextuser
Figure 1. Most requests are answered by an edge server close to the user; the origin only sees cache misses.

Getting users to the nearest edge

  • DNS-based: when the user looks up the site's name, the CDN's DNS answers with the address of an edge near the user's resolver.
  • Anycast: the same IP address is announced from many locations with BGP, and internet routing naturally delivers each user to a nearby one. Cloudflare and many DNS services use this.

Caching

The edge server checks whether it already holds a fresh copy of the requested object:

  • Cache hit: it answers immediately from the edge.
  • Cache miss: it fetches the object from the origin (your real server), sends it to the user and keeps a copy.

How long objects are kept depends on HTTP headers from the origin, mainly Cache-Control: max-age=86400, and on CDN rules. Static files such as images, CSS and JavaScript cache well; personalised pages usually should not be cached. When you update content, you purge the old copies or use new file names (versioning).

Beyond caching

  • DDoS protection: attack traffic is spread across the CDN's huge capacity instead of hitting your server.
  • Web application firewall rules and bot management at the edge.
  • TLS at the edge: the CDN handles certificates and modern protocols such as HTTP/3.
  • Edge computing: running small pieces of code at the edge (Workers, Functions) to personalise responses close to users.
  • Hiding the origin: users only see the CDN's addresses, so attackers cannot easily target the server directly (if the origin firewall only accepts the CDN).

Well-known CDNs include Cloudflare, Akamai, Amazon CloudFront, Fastly and Google Cloud CDN. This website itself is delivered through one.

Troubleshooting a site behind a CDN

  • Check response headers (curl -I) for the CDN's cache status, such as cf-cache-status: HIT or x-cache: Miss from cloudfront.
  • Seeing old content? Purge the cache or check the max-age.
  • Getting 52x errors from the CDN? The CDN could not reach your origin, often because the origin firewall blocks the CDN's addresses or its certificate is invalid.
  • Remember different users may hit different edges with different cached versions.

Real-world example: the school website on results day

A school's website crashed every year on exam results day as thousands of students and parents checked it at 8 a.m. Moving it behind a CDN with long cache times for the static pages meant 95 percent of requests were answered at the edge. The small origin server barely noticed the next results day.

Practice

What happens on a CDN cache miss?
The edge server fetches the object from the origin, returns it to the user and stores a copy for later requests.
How does anycast send users to a nearby edge?
The same IP address is announced from many locations, and BGP routing delivers each user to a nearby one.
Which HTTP header mainly controls how long a CDN may cache an object?
Cache-Control (for example max-age).

Key takeaways

  • CDNs serve content from edge servers close to users.
  • DNS or anycast routes users to the nearest edge.
  • Cache-Control headers decide what is cached and for how long; purge on updates.
  • CDNs also absorb DDoS attacks, add WAF rules and hide the origin.
Tracks your learning on this device only. See your progress on the learning paths.
Verified author✓ Valid
Issued to
Mohamed Fayas
Role
Founder of FM TecHub
Credentials
CCNABTEC HND Network EngineeringBEng (Hons) Computer Networking & Cloud Security
Issuer
FM TecHub · fmtechub.com

He writes practical, plain-English guides on networking, security and cloud.

More about the author →

Original content written by Mohamed Fayas for FM TecHub. © 2026 FM TecHub. You're welcome to share a link to this page; please don't copy the text elsewhere without permission.

Email updates: coming soon

New notes, tools and security news from FM TecHub by email, explained simply. Free. We're not collecting email addresses yet; see our privacy policy.

PortServiceStatus
SMTP/25Email updatesopening soon

Meanwhile, stay connected: