Lesson 02 · Scaling

Scalability: Growing Without Crashing

Your application is a success, congrats! But now, the servers are smoking. Two choices lie ahead: buy a beast of a machine or recruit an army of small servers. Welcome to the duel: Scale Up vs Scale Out.

1

The Duel: Vertical vs Horizontal

Vertical Scaling (Scale Up)
The Bodybuilder Analogy:
To lift heavier weights, you send your mover to the gym. He comes back stronger, bigger, capable of carrying 2 fridges at once.
  • Simple: no code changes required.
  • Limited: there is a physical limit (max CPU/RAM).
  • Expensive: high-end hardware costs a fortune.
Horizontal Scaling (Scale Out)
The Clone Army Analogy:
Instead of training a single mover, you hire 10 regular ones. Together, they empty the house in 5 minutes.
  • Unlimited: add as many servers as needed.
  • Resilient: if one server dies, the others are there.
  • Complex: requires Load Balancing and state management.
2

Visualization

Diagram of vertical vs horizontal scalability
Diagram illustrating vertical scalability (left) and horizontal scalability (right).
3

Comparison Table

CriteriaVertical (Scale Up)Horizontal (Scale Out)
CostExponential (Specialized Hardware)Linear (Standard Hardware)
ComplexityLow (Same architecture)High (Load Balancer, Sync)
Point of FailureSingle (SPOF)Redundant
LimitHardware Ceiling (Hardware limit)Virtually Unlimited
4

The Story: From 1 to 1 Million

Phase 1: The Garage (1-100 users)

Everything runs on your old laptop or a small $5 VPS.
Architecture: 1 Web Server + DB (Monolith).

Phase 2: The Success (10k users)

The site is slowing down. You buy a bigger server (more RAM, better CPU).
Action: Vertical Scaling. It holds... for now.

Phase 3: The Virality (1M+ users)

The world's biggest server is no longer enough. You buy 10 small servers and put a "gatekeeper" (Load Balancer) in front.
Action: Horizontal Scaling. Welcome to the big leagues.

5

Classic Pitfalls

Sticky Sessions

If you store the user session in Server 1's RAM, and the next request hits Server 2... the user gets logged out!
Solution: Redis (External Session Store).

The Hidden Cost

Scaling horizontally is cool, but managing 100 servers is expensive in maintenance (DevOps).
Solution: Serverless or Managed Services (AWS, Vercel) at the beginning.

6

In Interviews (The System Design Interview)

What to say

Never say "We'll just add more servers". Show that you understand the trade-offs.

The Reflex:"To start, Vertical Scaling is often sufficient and easier to manage. It's a good first step."
The Evolution:"As soon as we hit limits or need High Availability (HA), we switch to Horizontal Scaling with a Load Balancer."
The Trap:"Watch out for databases! Scaling a DB horizontally (Sharding) is much harder than scaling a web server (Stateless)."
7

Flash Quiz

Self-assessment
8

Your Turn

Mission: Transition to Horizontal

Draw an architecture that transitions from a single server (Monolith) to a horizontally scaled architecture.
Elements to include: Load Balancer, 3 Web Servers, 1 Database (single for now).

9

For the Curious (Bonus)

The End of Moore's Law?
For a long time, we could count on processors doubling in power every 2 years (Moore's Law). Today, this progression is slowing down due to physical limits. That's why Scale Out has become the norm for giants like Google or Facebook: we can no longer build a processor powerful enough to handle everything alone.
Scalability vs Elasticity
Important nuance!
Scalability: The system's ability to grow to handle more traffic.
Elasticity: The ability to grow AND shrink automatically (Auto-scaling). Useful in the Cloud to pay less at night when there are fewer people.