Stage 1 · Foundations · Easy · 12 min

Vertical and horizontal scaling

One server can only grow so far. See how to scale up with a bigger machine or scale out with more machines, and why scaling out needs stateless servers.

What each interview level is expected to know

Learn first: The client–server model

After this lesson you can:

  • Choose between a bigger machine and more machines, and say what each costs.
  • Explain why scaling out needs servers that keep no user state.
  • Find which tier is the real limit before adding servers to it.

Start here

See it in 60 seconds

A bigger server, or more servers

When one server is too busy, buy a bigger machine, which has a limit, or add more machines and share the requests.

Scene 1 of 6 · One server, too busy

Say one server handles about 1,000 requests a second; at 1,500 a second, requests wait and pages slow down.

UsersUsersServer, SLOWServer1,500 a secondSLOW
  • Users — healthy
  • Server — SLOW — 1,500 a second
Can handle, every server up
1,000
Can handle, one server down
0
Servers in all
1
  1. One server, too busy. Say one server handles about 1,000 requests a second; at 1,500 a second, requests wait and pages slow down.
  2. Buy a bigger machine. Vertical scaling swaps in a bigger machine with more CPU and memory: simple, with no code changes.
  3. Bigger has a ceiling. But in this example the largest machine is only about 8 times bigger, and if it fails, everything stops.
  4. Add more servers. Horizontal scaling adds more ordinary servers running the same code, with a load balancer in front.
  5. Share the requests. It sends each request to one server: 3 handle about 3,000 a second, or 2,000 with one down.
  6. Keep servers forgetful. This works only if no server keeps a user's session in its own memory, so any server can answer.
  7. Now you try. How many requests a second must the site handle? For example: 6,500 a second needs 7 servers doing the work, plus 1 spare: 8 in all. One machine 7 times bigger could also do it, but if it fails, everything stops.

Scene 1 of 6: One server, too busy. Say one server handles about 1,000 requests a second; at 1,500 a second, requests wait and pages slow down.

Key points

  1. Vertical scaling means a bigger machine: easy, with no code changes, until you reach the biggest one for sale.
  2. Horizontal scaling means more machines, with a load balancer in front to share the requests.
  3. Servers must not keep a user's session only in their own memory; keep it in a shared store.
  4. Keep one spare server, so that losing any one still leaves enough to carry the traffic.

Go deeper in the Scaling from 1 server to millions of users lab →

In plain words

Say one server handles 1,000 requests a second, and 1,500 arrive. You have two ways out. , also called scaling up, moves the app to one larger machine, with a faster CPU and more memory. , also called scaling out, runs the app on 3 machines. A in front shares the requests between them.

Each way has a limit. A bigger machine is the quick fix, but every machine has a maximum size, and moving to one usually means some downtime. More machines can keep growing, but only if a server does not need to remember earlier requests from the same user. The next request may land on a different machine, so and uploaded files must move to a shared store first.

The problem it solves

Scaling up is the easy start, but it ends. The largest machine you can rent has a fixed size, and one machine is one point of failure. Scaling out has no fixed ceiling for app servers, but it only works if any server can answer any request. So no server may keep data that another server needs, such as a login session.

Why it matters

Every server has a limit: at some traffic level its CPU or memory runs out. Most design questions come back to what you do then. The answer shapes the rest of the system, from the load balancer to where login sessions are kept.

A worked example

Say one server can handle 500 requests per second, and traffic grows to 4,500 requests per second. Horizontal scaling then needs about 4,500 ÷ 500 = 9 identical servers behind a load balancer to keep up.

Think of it like…

Think of moving boxes out of a house. Scaling up is one stronger person who carries more each trip. Scaling out is more people carrying boxes at the same time.

Where this analogy stops working

One bigger worker against many workers is the useful part. But any helper can pick up any box. A server can take any request only if it keeps no memory of earlier ones. So sessions and files must move to a shared store first.

Try it

See it working

Guided walkthroughOpen the full lab →

Step through one request at each stage

A user opens the profile of user:42. Pick a stage of the design, then press Next step. Each run ends on the limit that forces the next stage.

The design

With this design: With one server, a single restart took the whole site down. There was no second machine to take over.

Users, open profilesUsersopen profilesOne server, app and database, NOWOne serverapp and databaseGET /users/42NOW
  • Users — open profiles — healthy
  • One server — app and database — healthy — NOW — GET /users/42
  • Request
  • Answer
Step 1 of 4

Step 1 of 4 · One server

Done: A user opens the profile of user:42

What happens
The request goes straight to the one server.
Why
At the start, one server is the simplest design to build and run.
What changes
The server does all the work.
Next
The same machine runs the app and the database

Event log

3 more to go. Press a line to go back to that step.

Servers
1
Site up
yes

Step 1 of 4: One server. A user opens the profile of user:42. The request goes straight to the one server.

What this simplifies. Real systems change when a measured limit forces it, not at a fixed number of users. The order here is one common path. The tiers below show the same path with example sizes.

Grow the users, watch the bottleneck

Pick how many users the site has and which design serves them. Each design is built for one size and fills up at the next. The bar in each part shows how full it is.

Users
Design

At 10,000 users the busiest hour brings about 29 requests a second, and each dot stands for about 5 of them. The busiest part, the one server, is at 19% of capacity.

Users, 10,000 usersUsers10,000 usersOne server, app and databaseOne serverapp and database19% of capacity
  • Users — 10,000 users — healthy
  • One server — app and database — healthy — 19% of capacity
Lab time 3.0 s
Requests a second at peak
29
each dot stands for about 5
Refused
0%
Healthy: of sample requests, last 8 s
Slowest 5% wait at least
224 ms
40% of users are 150 ms away
Busiest part
The one server
19% of capacity

Numbers add up:arrived 17 = served 16 + refused 0 + in flight 1.The lab checks this sum as it runs, so a counting mistake would show here.

What design 1 adds

It is the cheapest and simplest design to build, run and change while you find out what users want.

  • DNS (Route 53). Turns the site name into the server address.
  • One server. Runs the web app and the database together.

What limits it next

One server is a single point of failure. A crash, a memory leak or a restart for an update takes the whole site down.

The next step

Move the database to its own server, and put two app servers behind a load balancer.

What it costs

No spare machine, and one machine can only grow so big.

Things to try

  1. Keep design 1 and move to 100K users. The one server needs about twice its capacity, so about half the requests are turned away.
  2. Now pick design 2. Every part is under its capacity again. Move to 1M users and the database becomes the busiest part.
  3. Keep going: design 3 at 1M, then 10M users, then design 4. Each design fixes one limit, and the next limit shows up at the next user count.
  4. Compare design 4 and design 5 at 10M users. Nothing is full in either, but with one region the slowest requests wait over 100 ms longer.

What this simplifies. The capacities are round examples, chosen so each design handles its own size and fills up at the next. Real limits depend on the code, the queries and the machines, and you find them by measuring. Each part stands for a group of machines. Users from 10,000 to 100,000,000 all make 100 requests a day, with the busiest hour 2.5 times the average.

Also try: Load balancer

Mechanics

How it works

To grow, you run more copies of the app and put a load balancer in front. The pictures follow a shop with two app servers, A and B.

  1. Keep no state on the server

    State is anything a server must remember between requests, such as who is logged in. If server A holds it, server B cannot help that user. So keep sessions and uploaded files off the server's own disk.

  2. Move the state to a shared store

    Pick a case to follow below

    With this case: The session lived on server A, so server B did not know the user and asked them to sign in again.

    User, signs in, shopsUsersigns in, shopsLoad balancer, any serverLoad balancerany serverServer A, session in memory, NOWServer Asession in memoryholds session s:91NOWServer B, session in memoryServer Bsession in memory
    • User — signs in, shops — healthy
    • Load balancer — any server — healthy
    • Server A — session in memory — healthy — NOW — holds session s:91
    • Server B — session in memory — healthy
    • Request
    • Signed out
    Step 1 of 3

    Step 1 of 3 · Server A

    Done: The user signs in on server A

    What happens
    The load balancer sends the sign-in to server A, which checks the password and makes a session.
    Why
    A session is what the shop remembers about a signed-in user between requests.
    What changes
    Server A keeps the session in its own memory.
    Next
    The next request goes to server B
    Session kept
    on server A
    Signed in on the next page
    no
    not yet

    Step 1 of 3: Server A. The user signs in on server A. The load balancer sends the sign-in to server A, which checks the password and makes a session.

    Put sessions in a shared store such as , and files in . Or send the user a that proves who they are, so no lookup is needed. Now every server is the same.

    In the picture, a user signs in on server A, and their next request goes to server B. With the session in A's memory, server B does not know them, so it asks them to sign in again.

    With a shared store, server B reads the same session and the user stays signed in. A load balancer can also send each user back to the same server, called sticky sessions. That hides the problem until that server restarts or fails.

  3. Add a load balancer

    A load balancer sits in front and spreads requests across the servers. Because the servers are the same, any of them can answer any request.

  4. Add and remove servers automatically

    Pick a case to follow below

    With this case: With two fixed servers, each stayed at 90% CPU, and pages slowed until someone added a server.

    Shoppers, more each minuteShoppersmore each minuteLoad balancer, spreads requests, NOWLoad balancerspreads requestsNOWServer A, app copyServer Aapp copyCPU 60%Server B, app copyServer Bapp copyCPU 60%
    • Shoppers — more each minute — healthy
    • Load balancer — spreads requests — healthy — NOW
    • Server A — app copy — healthy — CPU 60%
    • Server B — app copy — healthy — CPU 60%
    • Request
    Step 1 of 3

    Step 1 of 3 · Load balancer

    Done: Two servers share the traffic

    What happens
    1,200 requests a second arrive, 600 for each server.
    Why
    In this picture, one server is fully busy at 1,000 requests a second.
    What changes
    Each server's CPU is at 60%.
    Next
    Traffic grows to 1,800 requests a second
    Traffic
    1,200req/s
    Servers
    2
    CPU on each
    60%
    has room

    Step 1 of 3: Load balancer. Two servers share the traffic. 1,200 requests a second arrive, 600 for each server.

    watches a signal such as CPU use. For example, it adds servers when average CPU stays above 70%, and removes them when traffic drops. Adding servers this way is horizontal scaling. Buying a bigger server is vertical scaling.

    In the picture, one server is fully busy at 1,000 requests a second, a made-up number. A sale lifts traffic from 1,200 to 1,800 requests a second, so two servers run at 90% CPU each.

    With two fixed servers, they stay at 90% and pages slow down. The autoscaler adds server C, which brings each server down to 60%. A new server takes a minute or more to start. So the rule acts at 70%, before the servers are full.

  5. Check what the new servers share

    Pick a case to follow below

    With this case: Straight to the database, 8 servers asked for 160 connections. The database refused 60, and those servers failed their requests.

    App servers, 20 connections eachApp servers20 connections each4 serversDatabase, limit 100, NOWDatabaselimit 10080 of 100 usedNOW
    • App servers — 20 connections each — healthy — 4 servers
    • Database — limit 100 — healthy — NOW — 80 of 100 used
    • Connections
    • Refused
    Step 1 of 3

    Step 1 of 3 · Database

    Done: 4 servers open 80 connections

    What happens
    Each server keeps 20 database connections open and ready. This set is its connection pool.
    Why
    Opening a connection is slow, so a server opens a few once and uses them again.
    What changes
    The database allows 100 connections, so 80 fit.
    Next
    A sale doubles the servers to 8
    App servers
    4
    Connections asked for
    80
    Open at the database
    80
    limit 100
    Refused
    0
    none

    Step 1 of 3: Database. 4 servers open 80 connections. Each server keeps 20 database connections open and ready. This set is its connection pool.

    What these pictures simplify. These pictures use a made-up capacity: one server is fully busy at 1,000 requests a second. Real limits depend on the code and the machine. Real autoscalers also have a minimum and a maximum number of servers. In the last picture, 100 connections is the default limit in PostgreSQL, and the pool sizes are examples. A real pooler can also limit which database features the app may use.

    More app servers put more load on what they all share, most often the database. Each server keeps a few database connections open and ready, called a . A database allows only so many connections at once.

    In the picture, each server keeps a pool of 20, and the database allows 100 connections. That is the default limit in . Four servers hold 80, which fits.

    A sale doubles the servers to 8, and they ask for 160 connections. The database refuses 60, so the new servers fail their requests. Adding servers made the site worse.

    A pooler in between fixes this. The servers open their connections to the pooler, and it shares 40 real ones with the database. PgBouncer is a common pooler for PostgreSQL.

Use it when

  • Traffic that grows or changes through the day: add servers at the peak and remove them at night.
  • A service that must stay up when one machine fails: with several servers, the others carry on.

Skip it when

  • A small app that one modest server runs with room to spare: more servers only add parts that can break.
  • The database, at first: it holds state, so it cannot be copied like an app server. Scale it up, then look at replicas and .

Check yourself

What must be true before you can add more app servers behind a load balancer?

Judgement

Trade-offs and how it fails

What you give up

Cost
Many small servers often cost less than one very large one, and you pay only for what you run. But you also need a load balancer and a shared store for sessions.
Complexity
With many servers, sessions move to a shared store such as Redis, and logs must be collected in one place.

Failure modes

  • Sessions kept in one server's memory. A user logs in on server 1, the next request lands on server 2, and they are logged out.
  • Scaling the wrong tier: you add app servers, but the database was the slow part, so nothing gets faster.
  • Running out of database connections: every new app server opens its own pool, and together they pass the database's limit.

In the real world

  • Kubernetes can add or remove copies of a service automatically from CPU use, with its Horizontal Pod Autoscaler.
  • Stack Overflow has published its hardware list: for years it served the whole site from a few large servers, a case of scaling up first.

Trade-offs to be ready to discuss: Vertical vs horizontal scaling

Check yourself

When is moving to a bigger machine a reasonable first step?

Interview

What interviewers look for

  • Say it early: "The app servers keep no state, so I can add more of them behind a load balancer."
  • Say which part runs out first, such as the database, and how you would scale that part.

Say it out loud: What must be true of an app server before you can run many copies of it?

You run 3 servers behind a load balancer. Users log in, then get logged out at random. Each server keeps sessions in its own memory. What is the fix?

Expected depth by interview level

Levels describe the depth interviewers probe, not years of experience. Choose a level on the learning path to highlight it.

JuniorCore
Vertical vs horizontal scaling, and why stateless servers scale out.
MidCore
Scale each tier: app servers, caches, read replicas.
SeniorExpected
Know which tier breaks first, and why.
StaffUseful
Scaling as a cost decision, including when not to scale.

Practice

Apply it

Three harder questions

The first two use the idea on a new case. The last asks you to judge a design.

Apply it

Each server handles 1,000 requests a second and keeps no state. Traffic peaks at 4,500 a second. How many servers do you need at peak, with one spare?

Apply it

Autoscaling adds app servers when average CPU stays above 70%. Pages are slow. App servers sit at 30% CPU, and the database at 100%. What will autoscaling do?

Judge a design

An app keeps uploaded photos on each server's own disk. The team scales out to 5 servers. Which change lets any server answer any request, even after one server dies?

Next, Stage 2 starts with load balancers: how requests are spread across your servers.

Go deeper

Sources and further reading

First-hand sources to check this page against and to go further. They are standards, official docs, original papers, and guides from engineering and security teams. Each link was opened on 8 November 2026.