Lesson 8 of 16
26. CDNs

26.7 Can the CDN handle dynamic content?

3 min read+10 XP

In the warehouse: Modern warehouses don't just store cartons. They assemble gift boxes, add a name tag, and decide which nearby shop gets which van. Some work that used to happen at the factory now happens close to the customer.

In the system: Dynamic and personalised responses can't simply be cached, but a CDN still helps:

  • Faster connections to the origin. The edge keeps warm, optimised connections to your origin, so even uncached requests skip slow handshakes from the user's network.
  • Micro-caching. Cache "dynamic but shared" responses for 1 to 10 seconds: a homepage during the Big Book Sale, a "top sellers" list. Thousands of requests a second become one origin request every few seconds.
  • Split the page. Cache the shared shell (layout, book details) and fetch the personal bits (cart count, "Hi Asha") separately from the browser. Or assemble at the edge with Edge Side Includes.
  • Code at the edge. Platforms like Cloudflare Workers, CloudFront Functions and Lambda@Edge run small functions in the PoP: redirects, A/B test bucketing, auth token checks, header rewriting, image resizing, geolocation-based routing, and even rendering pages from edge-replicated data.
  • API caching. GET /books/42 (public JSON) can be cached like a page. Personal APIs (GET /me/orders) can't.

Keep edge code small and stateless; anything needing the main database still goes to the origin, and debugging code spread across hundreds of PoPs is harder.

Memory code: "Cache the shared part for seconds, and do the small jobs near the customer."