How CDN works

Edge servers, caching, performance and configuration: everything you need to know about content delivery networks

8 min

A CDN (Content Delivery Network) is a globally distributed network of servers that stores copies of your web content and serves it from the location closest to the user. Instead of every visit travelling to your server in Madrid, a user in Buenos Aires receives content from an edge server in South America.

CDNs are fundamental to modern web performance. They reduce latency, absorb traffic spikes, protect against DDoS attacks and directly improve the Core Web Vitals metrics that Google uses for SEO ranking. This guide explains how they work, how to configure them and which providers to consider.

What is a CDN and why does it matter?

Network latency (the time it takes for a request to travel from the user to the server and back) depends on physical distance. A server in Europe responds in ~30ms to a European user, but in ~200ms to a user in Asia or the Americas. A CDN reduces that latency by serving content from edge servers distributed worldwide.

Modern CDNs do not only cache static files (images, CSS, JavaScript). They can also cache HTML responses, execute logic at the edge (edge computing), automatically optimise images, apply compression and manage SSL certificates. They are a critical piece of any web architecture that prioritises performance.

How the distribution network works

When a user visits your website, the request is routed to the nearest edge server (PoP — Point of Presence). If that server has a cached copy of the requested resource (cache HIT), it returns it immediately without contacting your origin server. If it does not (cache MISS), it requests the resource from the origin, returns it to the user and stores a copy for future requests.

Major CDNs (Cloudflare, AWS CloudFront, Fastly, Akamai) have hundreds of PoPs worldwide. Cloudflare operates in over 310 cities, meaning virtually any user is less than 50ms from an edge server.

  • Cache HIT: the edge has the resource, response in <10ms
  • Cache MISS: the edge requests from origin, caches the response for future visits
  • TTL (Time To Live): how long a resource stays in cache before refreshing
  • Purge/Invalidation: force removal of a cached resource when content changes

Caching strategies

Cache configuration is where a CDN adds or subtracts value. A cache that is too aggressive serves stale content; one that is too short generates many MISSes and does not leverage the distribution network. The key is to define appropriate TTLs per resource type.

Versioned static assets (main.a1b2c3.js, styles.x7y8z9.css) can be cached indefinitely (1-year TTL) because the filename changes when the content changes. HTML should have a shorter TTL (seconds to minutes) to reflect content updates. Images are typically cached for days or weeks.

  • Versioned assets (JS, CSS with hash): 1-year TTL, immutable
  • HTML: short TTL (60s–300s) or stale-while-revalidate
  • Images: TTL of days to weeks, with URL-based invalidation
  • API responses: selective caching with Vary headers and cache keys
  • stale-while-revalidate: serve stale cache while refreshing in the background

Impact on performance and SEO

A well-configured CDN can reduce Time to First Byte (TTFB) from 200–500ms to under 50ms. This directly impacts Largest Contentful Paint (LCP) and the user’s perception of speed. Google uses Core Web Vitals as a ranking factor, making the CDN a technical SEO tool.

Beyond caching, modern CDNs apply automatic optimisations: Brotli/gzip compression, HTTP/2 and HTTP/3, Early Hints, image optimisation (WebP, AVIF, automatic resizing) and HTML/CSS/JS minification. Each optimisation reduces transferred bytes and improves load times.

Main CDN providers

Cloudflare is the most popular thanks to its generous free tier, its 310+ PoP network and additional features (WAF, DDoS protection, Workers for edge computing). AWS CloudFront integrates natively with the AWS ecosystem. Fastly stands out for its programmable cache with VCL/Compute@Edge and purge times under 150ms.

Vercel and Netlify include an integrated CDN in their deploy platform, ideal for JAMstack/headless projects. For high-traffic ecommerce, Akamai and Fastly offer the performance and SLA guarantees required by stores with millions of visits.

  • Cloudflare: generous free tier, WAF, Workers, 310+ PoPs
  • AWS CloudFront: native AWS integration, Lambda@Edge
  • Fastly: programmable cache, purge in <150ms, Compute@Edge
  • Vercel/Netlify: CDN integrated into the deploy platform
  • Akamai: enterprise, strict SLAs, oldest and most extensive network

Configuration and best practices

Minimum CDN configuration includes: defining the origin (your server or hosting service), configuring HTTPS with an SSL certificate (most CDNs manage this automatically), setting appropriate cache headers and verifying that compression is active.

Advanced best practices include: using custom cache keys for dynamic content, configuring stale-while-revalidate to balance freshness and performance, implementing automatic purge when new content is deployed, and monitoring cache hit ratio (target: >90%).

  • Mandatory HTTPS with a CDN-managed certificate
  • Correct cache headers: Cache-Control, ETag, Vary
  • Brotli compression enabled (better ratio than gzip)
  • Monitor cache hit ratio and optimise to >90%
  • Automatic purge integrated with the deploy pipeline

Key Takeaways

  • A CDN serves content from the edge server closest to the user, reducing latency
  • Caching strategy per resource type is key: immutable assets, HTML with short TTL
  • The Core Web Vitals impact makes CDN a technical SEO tool
  • Cloudflare, CloudFront and Fastly lead with different approaches
  • Monitor your cache hit ratio and aim to exceed 90%

Want to optimise your web performance?

We configure and optimise your CDN so your site loads fast anywhere in the world.