Pebellslearn by building
0%
RoadmapsMatrixCoursesSandboxSign in
Load Balancers  ›  Capstone Project

Horizontal Scaling

Horizontal Scaling 15 minHorizontal scaling adds more machines behind a load balancer instead of a bigger machine, and only works when servers are stateless, keeping sessions and data in shared stores.

Horizontal Scaling

Hop's dashboard server is at 100% CPU. There are two ways to get more capacity: buy a bigger machine, or buy more machines. The second is how large systems grow — but it only works if Hop's servers are built for it.

The rule

Grow by adding machines, and keep no state on any one of them.

Vertical scaling (scaling up) means a bigger machine: more CPU, more memory.

  • Simple — no code changes.
  • But there is a biggest machine you can buy, prices rise steeply near the top, and it is still one box that can fail.

Horizontal scaling (scaling out) means more machines of the same kind behind a load balancer.

  • Capacity grows by adding servers; you can also remove them when traffic drops.
  • Losing one server is survivable — the others carry on.
  • But it only works if any server can handle any request.

That last condition is the heart of it. A server is stateless when it keeps nothing about a user between requests in its own memory or disk. Anything that must last — sessions, uploaded files, data — goes into shared places every server can reach: a database, a cache service, object storage, or a signed token the client sends with each request.

The shortcut

Before adding servers, ask: "If this user's next request lands on a different server, does anything break?" If yes, find what that server is keeping to itself and move it to a shared store.

Scaling out Hop's dashboardStep 1 of 4
  1. Try adding servers

    Five dashboard servers behind round robin. Users start getting logged out at random.

Sticky sessions (a hash that pins each user to one server) can hide the problem, but when that server dies its users are logged out, and load spreads unevenly. Moving state out is the real fix.

Remember too that stateless servers push the pressure onto the shared stores. Scaling out Hop's servers is easy; the database behind them is where the next lessons of system design begin.

Drills

Answer fast — trust the rule.

quick drill

Which is horizontal scaling?

quick drill

What is a main weakness of vertical scaling?

quick drill

After scaling out, users are randomly logged out. What is the likely cause?

quick drill

Where should uploaded files go so that any server can serve them?

quick drill

Why are sticky sessions only a partial fix?

Remember

  • Grow by adding machines, and keep no state on any one of them.
  • Shortcut: "if the next request lands elsewhere, does anything break?" Move that state to a shared store.
  • Trap: sticky sessions hide the problem instead of fixing it.

Practice — level up

0/1 solved

Write your answer, then compare it with a rubric and a model answer.

ExplainScale Hop out

Hop's single dashboard server keeps logged-in users' sessions in its own memory and is at full CPU. Compare scaling it vertically and horizontally, explain why simply adding four more servers behind a round-robin load balancer would break logins, and describe the fix.