API Fundamentals Course
API Fundamentals
/
Intermediate

CDN Usage

Definition

Content Delivery Network. A globally distributed network of proxy servers that cache content physically closer to end users, providing high availability and extreme performance.

Explain Like I'm New

If your API server is in New York, a user in Tokyo has to wait 200 milliseconds just for the signal to cross the ocean. A CDN places 100 'mini-servers' around the world. The Tokyo user talks to a mini-server in Tokyo, getting the response in 5 milliseconds.

Real World Example

Cloudflare or AWS CloudFront. You put Cloudflare in front of your API. When users fetch `/api/static-product-list`, Cloudflare caches the JSON. The next 5 million users fetch it directly from Cloudflare, and your real server never even sees the traffic.

Common Use Cases

  • •Global scaling
  • •DDoS protection
  • •Static asset delivery

Terminal Output

bash / terminal
/* How a CDN intercepts an API request: [ USER IN TOKYO ] ---> [ CLOUDFLARE NODE IN TOKYO ] 1. Does Cloudflare have a fresh copy of /api/products? YES -> Return it instantly (5ms delay). Server doesn't know it happened. NO -> Proceed to Step 2. 2. Cloudflare forwards the request across the ocean to the real server. [ CLOUDFLARE ] ---> [ MAIN SERVER IN NEW YORK ] 3. Main Server generates the JSON and sends it back to Cloudflare. 4. Cloudflare saves a copy in Tokyo for the next user, and sends it to the user. */

Interview Questions

basic

  • Are CDNs primarily used to cache static data (like images and blog posts) or highly dynamic data (like live bank balances)?

intermediate

  • What does the term 'Edge Computing' mean in the context of CDNs?

Flash Cards

Question

Static or dynamic?

Click to reveal answer
Answer

Static data. CDNs are perfect for things that rarely change. You should NEVER cache a live bank balance on a CDN, because users would see outdated numbers.

Question

What is Edge Computing?

Click to reveal answer
Answer

Instead of just caching static files, modern CDNs allow you to run small pieces of JavaScript (Edge Functions) directly on their global servers. This allows you to run backend logic in Tokyo without having an actual backend server in Tokyo.