How it works
A content delivery network stores assets such as images, video, CSS, and JavaScript at distributed edge locations, which are servers close to users. On a miss, an edge fetches the asset from its origin, the server that holds the source copy, and caches it; later requests can be answered near the user until the cached copy expires.
Distance is the main benefit. As a rough example, a visitor in Sydney fetching an image from an origin in Virginia waits about 200 ms per round trip, while a nearby edge may answer in about 20 ms. A CDN also takes load off the origin. If a 200 KB image is requested one million times a day and the hit ratio is 95%, the origin serves 50,000 requests and 10 GB rather than 200 GB.
CDN delivery has transfer costs, so rarely used assets may bring little benefit. A changed file can be refreshed by invalidating the old object or by giving the new version a new URL, such as app.3f9a2c.js, which lets you cache it for a long time safely. Cloudflare, Amazon CloudFront, and Fastly all support both. Private files need extra care, such as signed URLs. Plan what the application should do if CDN delivery is temporarily unavailable.
A CDN shortens the path for cached assets. It does not automatically accelerate a dynamic request that still crosses the world to a distant application and database. If the HTML takes 800 ms because the server is far away, a faster image will not fix it.
International users report a slow page even though database queries are fast.
Measure which requests are slow. Serve static assets through a CDN near users; if dynamic requests still travel to a distant region, investigate the application path or regional placement. A CDN cannot fix every dynamic round trip.
Use this as a guide for self review; written answers are not graded.Keep in mind
- CDN caching targets static delivery; application caching targets repeated computation or data reads.
- Measure the slow request before choosing an edge solution.