A Content Delivery Network (CDN) is a geographically distributed group of servers that caches content close to end users. A CDN allows for the quick transfer of assets needed for loading Internet content including HTML pages, JavaScript files, stylesheets, images, and videos.
If your web server is located in New York, a user in Tokyo is approximately 10,800 km away. At the speed of light through fiber optic cable, a single round trip takes about 100-150ms just for the physics of the signal travel. Every image, CSS file, and JavaScript bundle requires a separate round trip.
A CDN solves this by placing copies of your static content on servers in Tokyo, London, Sydney, and hundreds of other cities. The Tokyo user downloads images from the Tokyo server (2-5ms latency) instead of from New York.
The content provider proactively uploads (pushes) content to the CDN servers. You are responsible for providing content, uploading it to the CDN, rewriting URLs, and managing expiration.
The CDN lazily fetches content from the origin server when the first user requests it. Subsequent requests are served from the CDN cache.
codingstuff.io/logo.png.logo.png from the origin server in New York.The biggest challenge with CDNs is ensuring stale content is updated. If you update your website's CSS, users might still see the old cached version from the CDN.
Solutions:
style.abc123.css). When the content changes, the filename changes, forcing the CDN to fetch the new version.Major CDN Providers: Cloudflare, AWS CloudFront, Akamai, Google Cloud CDN, Fastly.