Skip to content

Servers, Load Balancers & CDNs ​

Season 2 · Note 8

In Plain English (30-Second Refresher) ​

TL;DR

Behind a big app's one address there are many computers.

  1. A load balancer is the single front door. It spreads requests across servers and uses health checks to skip any that fail.
  2. Layer 4 balancers route by address and port; layer 7 balancers read the request itself (e.g. /scores vs /images).
  3. App servers do the work; a database keeps the data safe.
  4. A CDN (content delivery network) keeps copies of unchanging files (pictures, code, videos) in hundreds of cities, so most requests are answered in a few ms (milliseconds) instead of crossing an ocean.
  5. Autoscaling adds servers when traffic spikes.

The Mission We Follow ​

Your score has crossed the ocean. Now: which of Coin Dash's servers gets it, what happens if one has crashed, and how does the leaderboard page load fast for players everywhere?

Real-World Analogy: A Busy Head Office With Local Branches 📮 ​

In real lifeIn the data centreWhat it does
🛎️ The reception deskLoad balancerSends each visitor to a free clerk
🩺 "Still at your desk?"Health checkSkips clerks who don't answer
🧑‍💼 A clerkApp serverHandles the request
🗄️ The filing cabinetDatabaseKeeps records safe
🏬 Local branch warehousesCDN edge serversStock copies near customers
📞 Calling in extra staffAutoscalingMore servers for a rush

Visual Mental Model ​

The other end: a load balancer skips a failed server and sends the request to a healthy one that saves to the database, while a CDN edge in your city serves pictures from its cache

How It Works (Interactive Animated Flow) ​

The Other End
One front door, many servers, copies near you
🎯 Mission Save “score = 52” while server 1 has crashed.
START💻Youopen the leaderboard≈ 8 ms🌍Edge cachein your cityHEALTH ✓⚖️Load balancerone front doorDOWN🖥️Server 1not answeringOK🖥️Server 2healthy, freeSAVED🗄️Databasesaves score = 52pictures, codehit ✓scoreskip ✗send heresavemiss → fetch once

Layer 4 vs Layer 7 Load Balancers ​

Layer 4Layer 7
ReadsIP (Internet Protocol) address + portthe full web request (path, headers, cookies)
Can route /scores and /images differently?NoYes
Handles TLS (Transport Layer Security)?Passes it through, lockedUnlocks it to read the request
Speed / costFaster, cheaperSmarter, more work per request

What Belongs on a CDN? ​

✅ Great for a CDN❌ Send to the origin
Pictures, fonts, game code, videosSaving your score
Pages that are the same for everyoneYour account page, your password check
Big downloads (game updates)Anything that changes every second

Cache hit = the edge already has it (≈ 8 ms). Cache miss = the edge fetches it once from the origin, then serves everyone else.

Trade-offs ​

ChoiceUpsideDownside
Many servers + a load balancerNo single point of failure; easy to growMore moving parts; state must live in a shared database
CDNFast everywhere; absorbs traffic spikesCopies can be stale until they expire or are purged
AutoscalingPay for what you useTakes a minute or two to react; needs limits

Common Gotchas ​

Watch Out For

  • Don't keep important state on one server. If it's taken out of rotation, that data disappears. Use the database (or a shared cache).
  • Purge the CDN after a change, or players see the old picture until it expires.
  • Health checks must check something real ("can I reach the database?"), not just "is the computer on?".
  • A CDN doesn't speed up personal data. Your score still has to reach Coin Dash.

Quick Self-Check (Restore Your Memory) ​

1. Server 1 crashes during a tournament. What happens to your score?

The load balancer's health checks notice, take server 1 out of rotation, and send you to a healthy server. Nobody notices.

2. What should be served from a CDN, and why is it faster?

Files that are the same for everyone and rarely change (pictures, code). The edge is in your city, so the trip is a few milliseconds instead of crossing an ocean.

3. What can a layer 7 load balancer do that a layer 4 one can't?

Read the request itself, so it can route by path or header (e.g. /scores → score servers, /images → image servers).

🎬 Now Watch It Happen ​

2-minute episode

The season finale: ride along as the packet through the load balancer, a crashed server, the database and the CDN, then survive tournament night. S2 · E8 — The Other End →

Built for clear thinking and fast 2-minute refreshers.