SysDesignAtlas

Scalability Basics

Vertical vs horizontal scaling, why stateless services are the whole game, and the three-axis model that tells you which direction to scale next.

CoreEasy11 min readscalingarchitecture
Confidence

#What "scalable" actually means

A system is scalable if you can handle N times the load with roughly N times the resources — without redesigning it. That "without redesigning" clause is the entire difficulty. Almost any system handles 2× load fine. The question is whether getting to 100× requires new hardware or a new architecture.

The corollary worth holding onto: scalability is not performance. A system that serves one request in 1ms but collapses at 100 concurrent users is fast and unscalable. A system that takes 200ms but holds that at a million users is slow and scalable. They're different properties with different fixes, and conflating them is a common early stumble.

#Vertical scaling (scale up)

Buy a bigger machine. More cores, more RAM, faster disks.

Genuinely underrated. Modern hardware is enormous — a single server can have 128+ cores and multiple terabytes of RAM. A well-indexed Postgres instance on such a box handles tens of thousands of transactions per second and stores billions of rows. That covers the entire lifetime of most products.

Advantages: no distribution. Everything lives on one machine, so a whole class of problems never arises:

  • no partial failure — half your machines up and half down, with each side unsure what the other did;
  • no keeping several copies of the data in agreement;
  • no distributed transactions — one change that must succeed or fail on several machines at once;
  • no waiting on the network between machines.

Every distributed systems problem in this curriculum is one you don't have.

Limits:

  • A hard ceiling. You eventually run out of "bigger."
  • The price rises faster than the power — the top-end machine costs far more than twice the mid-range one.
  • It's a single point of failure and typically requires downtime to resize.

#Horizontal scaling (scale out)

Add more machines. This is what people mean by "scalable," and it introduces every hard problem in distributed systems: coordination, partial failure, consistency, and rebalancing.

Advantages: ten machines give you close to ten times the capacity; they can be cheap, ordinary servers; losing one still leaves the others running; and you can add or remove machines as traffic rises and falls (elasticity).

Costs: every request now depends on messages between machines, and networks drop and delay messages. Data must be split across machines (partitioned) or copied to several of them (replicated). And the operational work grows faster than the machine count — ten machines means ten things to deploy, monitor and debug, plus every way they can disagree with each other.

#The prerequisite: statelessness

Horizontal scaling of your application tier only works if any request can go to any server. That requires servers to hold no request-specific state in local memory — which is what "stateless" means. A stateless server remembers nothing between requests; everything it needs either arrives with the request or is fetched from somewhere shared.

The classic violation is the in-memory session:

Broken — state in server RAM • login → App-1 {session: alice} • next → App-2 {} → 401 • user is silently logged out • any server restart drops sessions Fixed — state externalised • login → App-N → Redis • next → App-M → Redis → ok • servers are interchangeable • scale out by adding machines
Horizontal scaling requires that any request can hit any server.

Two standard fixes:

  1. Externalize state — sessions in Redis, uploads in object storage, everything durable in the database. Application servers become interchangeable and disposable.
  2. Signed tokens — put the state in a token the client carries (a JWT: a small blob of user data, signed by you so it can't be forged). No lookup at all, but cancelling one early becomes hard, and its contents can go stale. Usually paired with short expiry plus a refresh token.

Sticky sessions — the load balancer always sends the same user to the same server, so the session in that server's memory is always there — are the tempting third option and mostly a trap:

  • Load stops spreading evenly. A server that happens to get a few heavy users stays overloaded, because the balancer isn't allowed to move them.
  • Deploys become disruptive. Restarting a server to ship new code wipes the sessions it holds.
  • A single crash logs users out. Everyone pinned to that server loses their session at once.

#The three axes

A useful model borrowed from the "scale cube": there are exactly three directions to scale, and you can combine them freely.

X — Clone add identical replicas Z — Partition shard users A–M / N–Z Y — Decompose split into services
The three axes of scaling. Real systems use all three at once.

X — cloning. Run N identical copies behind a load balancer. Cheapest and first. Solves "too many requests for one server's CPU" — each clone takes a share. Solves nothing about data volume, since every clone holds the same data.

Y — functional decomposition. Split by responsibility: auth service, feed service, media service. Each scales and deploys independently, and each can pick its own datastore. Costs: network calls between services, debugging a request that crosses several of them, and the risk of a distributed monolith — services split so badly that they still have to change and deploy together, so you pay for the network without getting the independence.

Z — data partitioning. Split the data itself; each node owns a subset. This is sharding, and it's the only axis that solves data volume and write throughput. It's also the most expensive to undo.

Real systems apply all three: a sharded database (Z), fronted by several stateless service types (Y), each running many replicas (X).

#Load, and the two kinds of it

"Scale" means nothing until you say which load. Always separate:

  • Read scale — solved with replicas and caches. Comparatively easy, because a read can be answered by any nearby copy, even one a fraction of a second out of date.
  • Write scale — solved with partitioning, batching, and async processing. Genuinely hard, because every write has to land in one official place (so two writes to the same thing are applied in a definite order) and be saved to disk there before you say "done". You can't just copy that place ten times.

A 100:1 read/write ratio (typical for social products) and a 1:1 ratio (typical for ingest/telemetry) demand different architectures. Establish this ratio in the first two minutes of any interview.

#Scaling by removing work

The most underrated technique. Before adding machines, ask what work can disappear:

  • Cache it — the fastest request is the one that never reaches your database.
  • Do it later — reply "got it, working on it" (202 Accepted), put the job on a queue, and finish it in the background. That turns how long the user waits into how much work per hour you get through, which is a far easier problem.
  • Do it in bulk — 1,000 individual inserts versus one batch insert of 1,000 rows can differ by 50× in cost.
  • Push it to the edge — a CDN serving static assets removes the majority of requests from your origin for many products.
  • Don't do it at all — approximate counts instead of exact ones, sample your telemetry, expire old data.

#What to say when asked "how would you scale this?"

A reliable ordering, cheapest and least disruptive first:

  1. Measure. Which resource is saturated — CPU, memory, disk IO, network, or a lock? Scaling the wrong axis does nothing.
  2. Optimize. A missing index, an N+1 query (fetching a list, then firing one more query per row instead of a single join), a response nobody capped the size of. Frequently a 10× win for a few hours of work.
  3. Cache. Kill the repeated reads.
  4. Scale up. Bigger box. Boring, effective, no new failure modes.
  5. Scale out reads. Read replicas, plus a CDN for static content.
  6. Async the writes. Queue everything that isn't needed for the response.
  7. Shard. Last, because it's hardest to reverse.

Walking down that list in order is the discipline itself: you scale by evidence rather than by reflex.

#Check yourself

What is the difference between scalability and performance?Show answer
Performance is how fast one request is. Scalability is whether N times the load needs only about N times the resources, without a redesign. A system can be fast and unscalable, or slow and scalable.
Why is vertical scaling "genuinely underrated"?Show answer
One big modern machine — 128+ cores, terabytes of RAM — runs a Postgres that handles tens of thousands of transactions a second, and it avoids every distributed-systems problem: partial failure, consistency, cross-node latency.
What does "stateless" ask of an app server, and why does scaling out depend on it?Show answer
It keeps nothing request-specific in its own memory between requests, so any request can go to any server. Then you scale by adding servers behind a load balancer.
Why are sticky sessions mostly a trap?Show answer
Pinning users to servers breaks load spreading, makes deploys disruptive, and turns one crash into visible logouts. Move the state out of the server instead.
Of the three scaling axes — clone, decompose, partition — which one helps with data volume and write throughput?Show answer
Partitioning (sharding), where each node owns a subset of the data. Clones all hold the same data, and decomposing splits code, not data.
Do the division: 100M requests a day is how many a second on average, and at a 3× peak?Show answer
About 1,160 a second on average (100M ÷ 86,400) and about 3,500 at peak — a few app servers and one well-tuned database.
Asked "how would you scale this?", what comes before adding machines?Show answer
Measure which resource is saturated, then optimise (missing indexes, N+1 queries), cache, and scale up. Only then add read replicas, make writes asynchronous, and — last — shard.
Amdahl's law: if 5% of the work can't run in parallel, what's the most speed-up any number of machines can give?Show answer
20× (1 ÷ 0.05). The serial part — one lock, one counter, one write path — sets the ceiling.

#What to carry forward

  • Scalability means N times the load costs about N times the resources without a redesign; it is not the same as speed.
  • Start vertical: one big machine avoids every distributed problem and covers most products for their whole life.
  • Stateless app servers make the app tier the easy part; the real difficulty lives in databases, caches and queues.
  • Always do the division — requests a day to requests a second — and separate read scale (replicas, caches) from write scale (partitioning, async).
  • Scale in order: measure, optimise, cache, scale up, replicate reads, queue writes, shard last.
00:00
/ 11m