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
In AI systems: Serving a model: batches, memory and queues
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.
- 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
- 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.
- Buy a bigger machine. Vertical scaling swaps in a bigger machine with more CPU and memory: simple, with no code changes.
- Bigger has a ceiling. But in this example the largest machine is only about 8 times bigger, and if it fails, everything stops.
- Add more servers. Horizontal scaling adds more ordinary servers running the same code, with a load balancer in front.
- Share the requests. It sends each request to one server: 3 handle about 3,000 a second, or 2,000 with one down.
- Keep servers forgetful. This works only if no server keeps a user's session in its own memory, so any server can answer.
- 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
- Vertical scaling means a bigger machine: easy, with no code changes, until you reach the biggest one for sale.
- Horizontal scaling means more machines, with a load balancer in front to share the requests.
- Servers must not keep a user's session only in their own memory; keep it in a shared store.
- 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. (Handling more work by moving to a bigger machine, with more CPU and memory.), also called scaling up, moves the app to one larger machine, with a faster CPU and more memory. (Handling more work by adding more machines and sharing the requests between them.), also called scaling out, runs the app on 3 machines. A (A server that receives every request first and passes each one to one of several servers behind it.) 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 (A record the server keeps for a logged-in user. The browser holds only its id, and sends it with every request.) 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
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.
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.
Move the state to a shared store
Pick a case to follow belowWith 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, shops User signs in, shops Load balancer, any server Load balancer any server Server A, session in memory, NOW Server A session in memory holds session s:91 NOW Server B, session in memory Server B session 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 3Step 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 kepton server ASigned in on the next pagenonot yetStep 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 (A widely used data store that keeps its data in memory, so it answers much faster than a database on disk. It is often used as a cache.), and files in (A huge, cheap store for files such as photos and videos. Each file is saved whole under a key, such as video.mp4.). Or send the user a (A short note that says who the user is and when it expires, with a signature that proves the server made it.) 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.
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.
Add and remove servers automatically
Pick a case to follow belowWith this case: With two fixed servers, each stayed at 90% CPU, and pages slowed until someone added a server.
Shoppers, more each minute Shoppers more each minute Load balancer, spreads requests, NOW Load balancer spreads requests NOW Server A, app copy Server A app copy CPU 60% Server B, app copy Server B app copy CPU 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 3Step 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
Traffic1,200req/sServers2CPU on each60%has roomStep 1 of 3: Load balancer. Two servers share the traffic. 1,200 requests a second arrive, 600 for each server.
(A program that adds copies when a signal such as CPU use is high, and removes them when it is low.) 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.
Check what the new servers share
Pick a case to follow belowWith 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 each App servers 20 connections each 4 servers Database, limit 100, NOW Database limit 100 80 of 100 used NOW - App servers — 20 connections each — healthy — 4 servers
- Database — limit 100 — healthy — NOW — 80 of 100 used
- Connections
- Refused
Step 1 of 3Step 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 servers4Connections asked for80Open at the database80limit 100Refused0noneStep 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 few database connections that an app server opens once and keeps ready. Each request borrows one, so it does not wait for a new one to open.). 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 (A widely used open-source SQL database.). 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 (Splitting one database's data into parts and keeping each part on a different machine. Each part is called a shard.).
Check yourself
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
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?
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
Apply it
Judge a design
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.
- Engineering guideThe Twelve-Factor App: ConcurrencyAdam Wiggins (Heroku)Scaling out by running more copies of a process instead of making one copy bigger.
- BookDesigning Data-Intensive ApplicationsMartin Kleppmann (O’Reilly)Chapter 1 explains load, how to describe it with numbers, and scaling up versus scaling out.