Appearance
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.
- A load balancer is the single front door. It spreads requests across servers and uses health checks to skip any that fail.
- Layer 4 balancers route by address and port; layer 7 balancers read the request itself (e.g.
/scoresvs/images). - App servers do the work; a database keeps the data safe.
- 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.
- 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 life | In the data centre | What it does |
|---|---|---|
| 🛎️ The reception desk | Load balancer | Sends each visitor to a free clerk |
| 🩺 "Still at your desk?" | Health check | Skips clerks who don't answer |
| 🧑💼 A clerk | App server | Handles the request |
| 🗄️ The filing cabinet | Database | Keeps records safe |
| 🏬 Local branch warehouses | CDN edge servers | Stock copies near customers |
| 📞 Calling in extra staff | Autoscaling | More servers for a rush |
Visual Mental Model
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.
Layer 4 vs Layer 7 Load Balancers
| Layer 4 | Layer 7 | |
|---|---|---|
| Reads | IP (Internet Protocol) address + port | the full web request (path, headers, cookies) |
Can route /scores and /images differently? | No | Yes |
| Handles TLS (Transport Layer Security)? | Passes it through, locked | Unlocks it to read the request |
| Speed / cost | Faster, cheaper | Smarter, more work per request |
What Belongs on a CDN?
| ✅ Great for a CDN | ❌ Send to the origin |
|---|---|
| Pictures, fonts, game code, videos | Saving your score |
| Pages that are the same for everyone | Your 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
| Choice | Upside | Downside |
|---|---|---|
| Many servers + a load balancer | No single point of failure; easy to grow | More moving parts; state must live in a shared database |
| CDN | Fast everywhere; absorbs traffic spikes | Copies can be stale until they expire or are purged |
| Autoscaling | Pay for what you use | Takes 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 →