Networking, APIs and CDNs

What happens between a click and your server: DNS, HTTP, API styles, and how a CDN moves content closer to users.

On the roadmap:Beginner · step 2: How the web works

Lesson 9 of 13 · 11 min read · quiz · exercise

The journey of a request

Before your code runs, a lot happens. When a browser loads https://shop.example.com:

Figure SDA-FND-09-1 · Request journey: DNS, CDN, origin · © forcsguy.com

  1. DNS turns the name into an IP address. Answers are cached at several levels for a time given by the record's TTL, so changes spread gradually.
  2. A connection is opened (TCP) and secured (TLS). Each step costs round trips, so long distances hurt.
  3. HTTP carries the request and response.

Latency is mostly physics: a round trip across an ocean costs over 100 ms no matter how fast your code is. The only fixes are fewer round trips and moving data closer to the user.

Optical fiber connections in network equipment: long distances are carried as light in glass fibersImage: Syced · CC0 · Source · Wikimedia Commons: Fujikura optic fiber at Science Museum

Name lookup is a short chain of questions, each answered by a more specific server:

Figure SDA-FND-09-2 · How a name becomes an address · © forcsguy.com

A nineteenth-century map of the first transatlantic telegraph cable; today's internet still crosses oceans on undersea cables, which is why distance costs latencyImage: Howe's Adventures & Achievements of Americans · Public domain · Source · Wikimedia Commons: Transatlantic submarine cable map

CDNs

A content delivery network is a worldwide set of servers (edges) that keep copies of your content close to users.

  • Great for static files: images, video, scripts, stylesheets, and often whole pages that rarely change.
  • Cuts latency, absorbs traffic spikes and shields your origin from load.
  • Controlled by cache headers (Cache-Control: max-age=...) and purge APIs when content changes.
  • Use a versioned file name (app.3f9a.js) so you can cache for a year and still ship updates instantly.

Figure SDA-FND-09-3 · Content delivery in tiers · © forcsguy.com

Before: everyone goes to the origin

After: a CDN serves copies near users

What changed

  • Users get files from a nearby location
  • The origin handles far fewer requests
  • Changed files need invalidation or versioned names

Choosing an API style

StyleStrengthWatch out for
REST over HTTP/JSONSimple, cacheable, universalOver-fetching, many round trips for complex screens
GraphQLClient asks for exactly the fields it needsQuery cost control, caching is harder
gRPCFast binary protocol, strong contractsNeeds tooling, awkward in browsers
SOAPXML messages with a formal contract (WSDL) and built-in standards for security and transactions, still common in banks and older enterprise systemsVerbose, heavier tooling, rarely chosen for new public APIs
WebSockets / SSEServer can push live updatesLong-lived connections need extra capacity and care

A good default is REST for public APIs, gRPC between internal services if you need speed, and WebSockets only where live push is truly needed.

Designing good APIs

  • Version them so old clients keep working.
  • Paginate list endpoints (cursor-based pagination stays stable as data changes).
  • Make writes idempotent with idempotency keys, so a retry does not double-charge.
  • Return clear errors with correct status codes.
  • Authenticate and rate limit at the edge, often in an API gateway that also handles routing, logging and TLS.

Figure SDA-FND-09-4 · API gateway in front of services · © forcsguy.com

More on this site

Check your understanding

Question 1 of 4

0 correct so far

What does DNS do?

Go deeper

Topics covered in this lesson

All topics

© 2026 forcsguy.com. Original lesson text and diagrams. Books and sites linked above belong to their authors.