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
- 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.
- A connection is opened (TCP) and secured (TLS). Each step costs round trips, so long distances hurt.
- 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.
Image: 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
Image: 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
| Style | Strength | Watch out for |
|---|---|---|
| REST over HTTP/JSON | Simple, cacheable, universal | Over-fetching, many round trips for complex screens |
| GraphQL | Client asks for exactly the fields it needs | Query cost control, caching is harder |
| gRPC | Fast binary protocol, strong contracts | Needs tooling, awkward in browsers |
| SOAP | XML messages with a formal contract (WSDL) and built-in standards for security and transactions, still common in banks and older enterprise systems | Verbose, heavier tooling, rarely chosen for new public APIs |
| WebSockets / SSE | Server can push live updates | Long-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
Related reading
- High Performance Browser NetworkingIlya Grigorik · O'ReillyBooks
- HTTP/3: the past, the present, and the futureCloudflareBlogs
- MDN: HTTP cachingMDN contributors · MozillaDocumentation
- Cloudflare BlogCloudflare engineers · CloudflareBlogs
Show 6 moreShow fewer
- The Road to QUICCloudflareBlogs
- Flannel: An Application-Level Edge Cache to Make Slack ScaleSlack Engineering · SlackCase Studies
- Cloudflare Learning Center: What is a CDN?CloudflareDocumentation
- Cloudflare EngineeringCloudflare engineers · CloudflareBlogs
- Justin.tv's Live Video Broadcasting Architecture - High Scalability -High Scalability engineers · High ScalabilityCase Studies
- Service Workers at SlackSlack engineers · SlackCase Studies
Check your understanding
Question 1 of 4
0 correct so far
What does DNS do?
Go deeper
- High Performance Browser Networking by Ilya Grigorik: free online; how TCP, TLS and HTTP actually behave
Topics covered in this lesson
Practise it: Answer repeats at the edge
Everything below is already set up for this lesson: change the design, run the traffic, and see whether you meet the goal.
- 1The task
- 2Build and test
A link goes viral: 8,000 requests per second for the same few items.
Goal: Under 1% errors with at most 12 app servers and under $2,000 a month.
Servers alone cannot do it. Where can a repeated answer be served before it reaches them?
Try it yourself
Trace what happens, step by step, when a user in Sydney opens https://shop.example.com for the first time, and say where a CDN and a cache could save time.
Click what a strong design here would need:
Next course
© 2026 forcsguy.com. Original lesson text and diagrams. Books and sites linked above belong to their authors.