Skip to content

Chapter 7: DNS, CDN & Load Balancing


Metadata Card

ItemContent
Difficulty(Medium)
PrerequisitesChapter 1 (Layering Model); Chapter 4 (HTTP)
KeywordsDNS, A/AAAA/CNAME records, recursive/iterative queries, Anycast, CDN, edge nodes, L4/L7 load balancing, consistent hashing, Round Robin
Python3.8+
Code~100 lines

Your Progress

"You discover an invisible navigation system on the post road — when you say 'google.com', DNS (Domain Name Resolution Array) translates it into post road coordinates. CDN (Content Distribution Post Road) copies spell scrolls to the beacon tower closest to you. Load balancing distributes mana traffic across multiple backend beacon towers."

DNS — World's Largest Distributed K/V Store

            ┌───────────────────────┐
            │   Root DNS Servers    │  (13 logical groups, Anycast)
            │      (.)              │
            └────────┬──────────────┘

            ┌────────┴──────────────┐
            │   TLD DNS Servers     │  .com / .org / .cn / .io ...
            │      (TLD)            │
            └────────┬──────────────┘

            ┌────────┴──────────────┐
            │  Authoritative DNS    │  Authoritative records for example.com
            │  (Authoritative)      │
            └───────────────────────┘

Recursive vs Iterative:

  • Recursive: Client says "look up www.example.com and tell me the answer" — does nothing, waits for result
  • Iterative: Recursive resolver asks each server level — multiple round trips

DNS Record Types & TTL

TypeFull NamePurposeExample
AAddressDomain → IPv4example.com → 93.184.216.34
AAAAIPv6 AddressDomain → IPv6example.com → 2606:2800:220:1:248:1893:25c8:1946
CNAMECanonical NameDomain → another domain (alias)www.example.com → example.com
MXMail ExchangeDomain → mail serverexample.com → mail.example.com (priority 10)
NSName ServerDomain → authoritative DNSexample.com → ns1.example.com
TXTTextArbitrary text storageSPF, domain verification
SOAStart of AuthorityZone authority info

CDN — Putting the World at Your Doorstep

Architecture: Edge nodes (POP) around the world cache content. Users fetch from the nearest edge node.

Three elements:

  1. Edge/POP Node: Cache servers deployed globally
  2. Origin Pull: If edge doesn't have the resource (cache miss), it pulls from origin
  3. Anycast Routing: Multiple edge nodes share one IP; user traffic automatically routes to "nearest" node

Load Balancing — Taming Traffic

L4 vs L7:

FeatureL4 (Transport)L7 (Application)
Working LevelBased on IP + PortBased on HTTP content (URL, Header, Cookie)
PerformanceVery high (pure kernel forwarding)Lower (needs to parse application protocol)
FlexibilityLow — only IP/PORT basedHigh — URL path, user identity, content type
ExamplesLVS, IPVSNginx, HAProxy, Envoy, Traefik

Common Algorithms: Round Robin, Weighted RR, Least Connections, IP Hash, Consistent Hashing.

Consistent Hash

This pattern maps servers onto a virtual ring (0 ~ 2^32-1). When adding/removing a server, only neighboring nodes are affected — only K/N keys need migration.


Traveler's Notes

DNS + CDN + Load Balancing form the entry skeleton of the modern internet. When you visit any large website, all three are working within the first second. Remember: DNS isn't just a phonebook — it's a distributed, fault-tolerant, hierarchically cached key-value store that handles billions of queries per second.

Built with VitePress | Software Systems Atlas