Thuta Learning
IntermediateProgrammingintermediate

CDN and Edge Caching

What you'll walk away with

  • Explain the core ideas behind CDN and Edge Caching
  • Study the sample diagram/code and analyze its trade-offs
  • Apply the technique correctly to the Tutorial Platform and production scenarios

Build the mental model

A prior lesson covered application-level caching — storing computed results in memory or Redis to avoid redoing work on the same server. CDN and edge caching solves a different problem: physical distance. Even a perfectly fast origin server in, say, the US takes real time to answer a request from a user in Yangon, because network packets are bound by the speed of light and the number of network hops — no amount of server-side optimization removes that geography. A CDN solves this by deploying edge servers in many regions worldwide, each holding a cached copy of static (and sometimes dynamic) content; a user's request gets routed to the nearest edge server rather than crossing oceans to the origin, cutting round-trip latency dramatically and reducing load on the origin since it only needs to serve edge servers, not every individual user. The trade-off is freshness: an edge cache can serve slightly stale content until it re-validates with the origin (governed by a TTL or cache-invalidation signal), so CDNs are best suited to content that doesn't change every second.

Connect it to a real scenario

The Tutorial Platform serves lesson videos, images, and static assets to learners across many countries. Without a CDN, a learner in Yangon watching a video hosted on a single US-based origin server suffers a multi-hundred-millisecond round trip per request; with a CDN, the video is cached on an edge server in or near Southeast Asia, and subsequent viewers in the region get near-local latency. Lesson text content, which changes when an instructor edits it, uses a short TTL so edges refresh quickly, while immutable assets like course icons and video files use a long TTL since they rarely if ever change — matching CDN caching aggressiveness to how often each asset type actually changes.

Try the working example

text
WITHOUT CDN                              WITH CDN
                                          +------------------+
+------------------+                     |  Origin Server   |
|  Origin Server    |                    |     (US)         |
|     (US)          |                    +------------------+
+------------------+                        /       |      \
   ^      ^      ^                    edge sync  edge sync  edge sync
   |      |      |                       /          |          \
   |      |      |                +--------+   +--------+   +--------+
 Yangon  Berlin  Tokyo             | Edge   |   | Edge   |   | Edge   |
 (280ms)(120ms)(180ms)             | SE Asia|   | Europe |   | Japan  |
                                    +--------+   +--------+   +--------+
                                       ^              ^            ^
                                       |              |            |
                                     Yangon         Berlin        Tokyo
                                     (15ms)         (10ms)       (8ms)

Latency without CDN: 120-280ms (crosses ocean every request)
Latency with CDN: 8-15ms (served from nearby edge)
You should see
The diagram shows that without a CDN every request crosses an ocean to the origin with high latency, while a CDN serves from a nearby edge with far lower latency.

5-minute try-it

Categorize three Tutorial Platform asset types — (1) course icon SVG, (2) lesson video, (3) quiz score API response — by CDN caching TTL, explaining which should be cached long, short, or not at all.

One important caution

An instructor urgently fixes lesson content, but a long CDN TTL means users keep seeing the stale version for a while — without a cache-invalidation mechanism, this can persist unexpectedly long.

Accidentally caching user-specific or sensitive data (like a personal quiz score) at the CDN edge can leak one user's data to a different user requesting from the same edge — a real security risk.

Wikipedia — Content delivery networkSystem Design

Easy traps

  • An instructor urgently fixes lesson content, but a long CDN TTL means users keep seeing the stale version for a while — without a cache-invalidation mechanism, this can persist unexpectedly long.
  • Accidentally caching user-specific or sensitive data (like a personal quiz score) at the CDN edge can leak one user's data to a different user requesting from the same edge — a real security risk.
  • Validate your load/traffic assumptions before applying a design decision directly to a production system.

Exercise

Categorize three Tutorial Platform asset types — (1) course icon SVG, (2) lesson video, (3) quiz score API response — by CDN caching TTL, explaining which should be cached long, short, or not at all.

You'll know it worked when: The diagram shows that without a CDN every request crosses an ocean to the origin with high latency, while a CDN serves from a nearby edge with far lower latency.

CDN and Edge Caching | Thuta Learning