Back to Blog
CDNInfrastructureWeb Fundamentals

CDNs Explained: Why Your Site Needs One

Code436 min read
HOW A CDN DELIVERS YOUR CONTENTWITHOUT CDNOrigin ServerNew York, USUser: Tokyo~220msUser: London~120msUser: Sydney~280msAll requests → originWITH CDNOrigin ServerNew York, USEdge: TokyoEdge: LondonEdge: SydneyUser: Tokyo~12msUser: London~8msUser: Sydney~10msServed from nearest edgeHigh latency (no CDN)Low latency (CDN edge)Latency reduction: up to 95%
Without a CDN, every request travels to a single origin server. With a CDN, content is served from the nearest edge node.

What Is a CDN?

A Content Delivery Network (CDN) is a globally distributed network of servers that delivers your website's content from the location closest to each visitor. Instead of every request traveling across the world to reach your origin server, a CDN caches copies of your assets — images, stylesheets, scripts, and even entire pages — on servers spread across dozens or hundreds of locations worldwide.

The concept is straightforward: the farther data has to travel, the longer it takes. If your server is in New York and a visitor is in Tokyo, every request makes a roughly 14,000-kilometer round trip. A CDN eliminates most of that distance by serving content from a node in or near Tokyo instead.

A Brief History

The idea of distributed content delivery emerged in the late 1990s, when the web was growing faster than the infrastructure could handle. In 1998, Akamai Technologies was founded at MIT to solve a specific problem: how do you deliver web content at scale without overwhelming origin servers? Their approach — caching content at the network's edge — became the blueprint for the entire CDN industry.

For the first decade, CDNs were expensive and primarily used by major media companies and enterprises. That changed around 2010 when Cloudflare launched a free tier, making CDN technology accessible to anyone with a website. Today, CDNs serve the majority of all web traffic. Services like Cloudflare, AWS CloudFront, Fastly, and Vercel's Edge Network have made content delivery a commodity — fast, affordable, and often free for small sites.

How a CDN Works

When you put a CDN in front of your website, here's what happens when a visitor requests a page:

  1. DNS resolution. The visitor's browser performs a DNS lookup for your domain. Instead of resolving to your origin server, it resolves to the CDN's network, which uses geolocation and latency data to route the request to the nearest edge server.
  2. Cache check. The edge server checks whether it already has a cached copy of the requested content. If it does (a cache hit), it serves the content immediately — no contact with your origin server is needed. Response times for cache hits are typically under 20 milliseconds.
  3. Origin fetch (cache miss). If the edge server doesn't have the content (a cache miss), it fetches it from your origin server, serves it to the visitor, and caches a copy for future requests. Subsequent visitors in that region get the fast, cached version.
  4. Cache expiration. Cached content doesn't live forever. Each asset has a TTL (time-to-live) that determines how long the edge server keeps it before checking the origin for a fresh copy. You control TTL values through cache headers, giving you fine-grained control over how fresh your content stays.

The result: most of your visitors get content from a server that's geographically close to them, and your origin server handles a fraction of the traffic it otherwise would.

Why Your Site Needs a CDN

Whether you're running a personal blog or a business-critical application, a CDN addresses three things you should care about:

Performance

Speed is the most obvious benefit. A CDN can reduce page load times by 50% or more for visitors far from your origin server. This matters because load time directly impacts user behavior — 53% of mobile visitors abandon a site that takes longer than 3 seconds to load. Faster load times also mean better search engine rankings, since Google uses page speed as a ranking signal through Core Web Vitals.

CDNs also reduce latency for dynamic content through techniques like connection pooling, HTTP/2 multiplexing, and TLS session resumption. Even when content can't be fully cached, the CDN optimizes the connection between the edge and your origin.

Reliability

A single server is a single point of failure. If your origin goes down, your site goes dark. A CDN adds redundancy — if one edge server fails, traffic is automatically routed to the next closest one. Many CDNs can also serve stale cached content while your origin is temporarily unavailable, keeping your site functional during outages.

CDNs also absorb traffic spikes. Whether you get featured on Hacker News or run a flash sale, the CDN's distributed network handles the surge without overwhelming your origin server. Without a CDN, a viral moment can crash your site at exactly the wrong time.

Security

Modern CDNs do more than cache files. They act as a shield between the internet and your origin server. Most CDN providers include DDoS protection that absorbs malicious traffic at the edge before it ever reaches your infrastructure. Cloudflare, for example, routinely mitigates attacks exceeding 1 Tbps — volumes that would instantly take down any single server.

CDNs also simplify SSL/TLS management. They handle certificate provisioning, renewal, and termination at the edge, meaning your visitors get encrypted connections without you managing certificates on your origin server.

What a CDN Caches

Not all content is treated the same by a CDN. Understanding what gets cached and what doesn't helps you get the most out of it:

  • Static assets — Images, CSS files, JavaScript bundles, fonts, and videos. These rarely change and are ideal for caching. Most CDNs cache these aggressively by default.
  • HTML pages — Static HTML pages can be cached entirely. For dynamic sites, you can cache the page shell and load personalized content client-side, or use edge-side includes to mix cached and dynamic content.
  • API responses — Read-heavy API endpoints that return the same data for many users (product catalogs, public feeds) can be cached at the edge. Write operations and personalized responses bypass the cache.
  • Dynamic content — User-specific content (dashboards, shopping carts, authenticated pages) typically isn't cached. However, the CDN still improves performance through optimized routing and connection reuse.

Choosing a CDN

The CDN market has matured significantly. Here are the main options and who they serve best:

  • Cloudflare — The most popular choice for small to mid-size sites. Their free tier is remarkably generous, including unlimited bandwidth, DDoS protection, and a global network spanning 300+ cities. If you're not sure where to start, start here.
  • AWS CloudFront — Tightly integrated with the AWS ecosystem. If you're already on AWS, CloudFront is the natural choice. Pay-as-you-go pricing works well for variable traffic.
  • Fastly — Known for instant cache purging and edge computing capabilities. Popular with media companies and high-traffic sites that need real-time cache invalidation.
  • Vercel / Netlify Edge — Built into modern deployment platforms. If you deploy a Next.js or static site to Vercel or Netlify, you get CDN delivery automatically. Zero configuration required.

For most sites, the deciding factors are cost, ease of setup, and integration with your existing infrastructure. All major CDNs deliver excellent performance — the differences are in features, pricing models, and developer experience.

Practical Takeaways

A CDN is one of the highest-impact, lowest-effort improvements you can make to your web infrastructure. Here's what to keep in mind:

  • Use a CDN for every production site. There's no good reason not to. Free tiers from providers like Cloudflare make it cost-effective for any size site. The performance and security benefits are immediate.
  • Set proper cache headers. Your CDN is only as effective as your cache configuration. Set long TTLs for static assets (images, fonts, CSS) and shorter TTLs or no-cache for dynamic content. Use versioned filenames (e.g., styles.abc123.css) so you can cache aggressively and still deploy updates instantly.
  • Monitor your cache hit ratio. This is the single most important CDN metric. A good cache hit ratio is 90% or higher, meaning 9 out of 10 requests are served from the edge without touching your origin. If it's low, review your cache headers and caching rules.
  • Use the CDN's security features. Enable DDoS protection, configure WAF rules if available, and let the CDN handle SSL/TLS. These are often included for free and significantly improve your security posture.
  • Test from multiple locations. Use tools like WebPageTest or Pingdom to measure load times from different regions. This helps you verify that the CDN is working and identify any regions with suboptimal performance.
  • Understand cache invalidation. When you deploy updates, you need cached content to refresh. Most CDNs offer manual purge options, but the cleanest approach is using content-based hashing in filenames so new deployments automatically serve fresh assets without purging.

A CDN sits between your users and your server, making everything faster, more reliable, and more secure. It's foundational infrastructure — the kind of thing that, once set up, quietly improves every interaction a visitor has with your site. If you don't have one yet, it should be next on your list.

Want to understand the security layer that protects data between your CDN and your users? Our next article on SSL/TLS will cover how HTTPS actually works. In the meantime, make sure your DNS foundation is solid — it's the first step in every request your CDN handles.

Need help with your infrastructure?

Whether it's DNS, deployment, or full-stack architecture — Code43 can help you get it right.

Book a Consultation