Day 5 of 5
⏱ ~60 minutes
Networking for Developers — Day 5

Load Balancers and CDNs

How load balancers distribute traffic, CDN edge nodes, HTTPS/TLS termination, and setting up Cloudflare.

Load Balancers

A load balancer sits in front of your servers and distributes incoming requests across them. Without one, a single server handles everything — one failure takes down the site.

Load Balancing Algorithms
Round Robin: 1→2→3→1→2→3 (simple, even distribution)
Least Connections: route to the server with fewest active connections
IP Hash: same client always goes to same server (session affinity)
Weighted: server A gets 70% of traffic, server B gets 30%
Nginx as Load Balancer
upstream app_servers {
  least_conn;  # least connections algorithm
  server app1.example.com:3000;
  server app2.example.com:3000;
  server app3.example.com:3000;
}

server {
  listen 80;
  location / {
    proxy_pass http://app_servers;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
  }
}
CDNs
# CDN = Content Delivery Network
# Copies your static assets to edge servers worldwide
# User gets content from nearest edge, not your origin server

# Cloudflare: free tier, DNS + CDN + DDoS protection
# Add your domain → change nameservers to Cloudflare
# All traffic routes through Cloudflare edge

# Cloudflare handles:
# - Static asset caching
# - DDoS protection
# - TLS termination (HTTPS for free)
# - Firewall rules
# - Bot protection
ℹ️
Cloudflare's free tier is remarkably capable. For most sites: point your DNS to Cloudflare, enable the proxy (orange cloud), and you instantly get a CDN, HTTPS, and DDoS protection. Takes 5 minutes.
📝 Day 5 Exercise
Set Up Cloudflare
  1. A
  2. d
  3. d
  4. a
  5. d
  6. o
  7. m
  8. a
  9. i
  10. n
  11. (
  12. o
  13. r
  14. s
  15. u
  16. b
  17. d
  18. o
  19. m
  20. a
  21. i
  22. n
  23. )
  24. t
  25. o
  26. C
  27. l
  28. o
  29. u
  30. d
  31. f
  32. l
  33. a
  34. r
  35. e
  36. .
  37. E
  38. n
  39. a
  40. b
  41. l
  42. e
  43. t
  44. h
  45. e
  46. p
  47. r
  48. o
  49. x
  50. y
  51. f
  52. o
  53. r
  54. t
  55. h
  56. e
  57. A
  58. r
  59. e
  60. c
  61. o
  62. r
  63. d
  64. .
  65. V
  66. e
  67. r
  68. i
  69. f
  70. y
  71. H
  72. T
  73. T
  74. P
  75. S
  76. w
  77. o
  78. r
  79. k
  80. s
  81. (
  82. C
  83. l
  84. o
  85. u
  86. d
  87. f
  88. l
  89. a
  90. r
  91. e
  92. p
  93. r
  94. o
  95. v
  96. i
  97. s
  98. i
  99. o
  100. n
  101. s
  102. a
  103. c
  104. e
  105. r
  106. t
  107. )
  108. .
  109. C
  110. h
  111. e
  112. c
  113. k
  114. t
  115. h
  116. e
  117. e
  118. d
  119. g
  120. e
  121. c
  122. a
  123. c
  124. h
  125. e
  126. h
  127. i
  128. t
  129. r
  130. a
  131. t
  132. e
  133. i
  134. n
  135. t
  136. h
  137. e
  138. A
  139. n
  140. a
  141. l
  142. y
  143. t
  144. i
  145. c
  146. s
  147. d
  148. a
  149. s
  150. h
  151. b
  152. o
  153. a
  154. r
  155. d
  156. .

Day 5 Summary

  • Load balancers distribute traffic across multiple servers for reliability and scale.
  • CDNs cache content at edge locations globally — users get the nearest copy.
  • Cloudflare free tier = CDN + HTTPS + DDoS protection + firewall. Use it for every site.
  • TLS termination at the load balancer/CDN means your origin servers don't need to handle HTTPS.
Finished this lesson?