Scalability: Vertical vs Horizontal

How systems grow with traffic: a bigger server or more servers, and why stateless design wins.

Beginner6 min read
Language
Theme
Vertical (scale up)add CPU/RAM to one machineHorizontal (scale out)Server 1Server 2Server 3LBmore machines + load balancerStateless winsany server, any request
Key idea at a glance
INTERACTIVE

Playground: back-of-envelope capacity calculator

The interview estimation skill, as a tool. Move the sliders and watch QPS, storage and bandwidth fall out: the same math you will do on a whiteboard.

What "scale" means, precisely

A system scales when you can grow its capacity by adding resources instead of redesigning it. Two kinds of growth hurt differently: more users (more concurrent requests, more connections) and more data (bigger tables, slower queries, longer backups). A good design names which one it is solving.

Vertical scaling (scale up)

Buy a bigger machine: more CPU, more RAM, faster disk. A modern top-end server can have 128 cores and 2 TB of RAM, so "just get a bigger box" takes you surprisingly far. Entire startups run on one large Postgres instance.

Why people still choose it: zero code changes, no distributed-systems complexity, strong consistency for free, ops stay simple.

The hard limits:

  • There is a ceiling: you cannot buy an infinitely big machine.
  • One machine is a single point of failure. Restart = downtime.
  • Cost grows super-linearly: the biggest instances cost far more per unit of power than mid-size ones.

Horizontal scaling (scale out)

Add more ordinary machines and spread traffic with a load balancer. No ceiling: add the 10th server like you added the 2nd. Failure of one server removes 1/N of capacity, not 100%.

The price: statelessness. If any server can take any request, no server may hold request-specific state. Logged-in sessions, carts, in-memory caches: all of it moves to a shared store (Redis) or the client (JWT). This one constraint shapes the entire application tier.

Worked example: sessions done wrong and right

v1: login session stored in server memory. LB sends request 1 to server A (login works), request 2 to server B ("who are you?"). Broken. Two fixes: sticky sessions (LB pins user to A, but if A dies the session dies too, and load spreads unevenly), or stateless: session in Redis, any server reads it in ~1 ms. The stateless version survives server death, deploys and autoscaling. This is why "stateless app tier" is the default answer.

Numbers to carry

  • One well-tuned app server: ~1k-10k simple RPS; one well-tuned Postgres: ~10k-100k simple reads/sec (mostly from its cache).
  • Autoscaling reaction time: minutes (provision + boot + warm). Traffic spikes arrive in seconds. Pre-scale for known events.
  • Each new tier (cache, queue, replica) is another thing to operate: scale in steps, not all at once.

The scaling ladder (the order to climb)

  1. One server does everything (works to ~1k users).
  2. Split the database onto its own machine.
  3. Add app servers behind an LB (stateless first!).
  4. Add a cache (biggest win per rupee).
  5. Add read replicas for the DB.
  6. Shard the DB only when writes truly exceed one primary.

Jumping straight to microservices and sharding from step 1 is the most common resume-driven design mistake.

Common interview traps

  • "Add more servers" without making the app stateless first.
  • Forgetting the database: scaling the app tier 10x while one DB handles all writes.
  • Autoscaling assumed to react instantly.

Interview Q&A

Q: Your API went from 1k to 1M users and is timing out. First three things you check?
A: (1) The database: slow query log and connection pool saturation, since DBs are usually the first wall. (2) Whether hot data is cached: a 90% cache hit rate can remove 90% of DB load. (3) Whether the app tier is stateless so more servers can be added behind the LB.

Q: When is vertical scaling the right answer?
A: Early stage, or stateful workloads like the primary DB where horizontal scaling costs consistency and complexity. A bigger primary + read replicas beats premature sharding almost every time.

Key takeaways

Interview pointer

When scale comes up, say: 'I will keep the app tier stateless so it can scale horizontally behind a load balancer, with state in Redis/database.' That one line shows the fundamentals are in place.