Course contents

01. System Design Fundamentals Lesson 8 of 8

Scalability

Grow one server to many: scale up until the ceiling, scale out stateless servers, then find the shared database that stops linear scaling and relieve it.

14 minBeginner10 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • A scalable system grows capacity by adding resources, roughly in proportion to load.
  • Scaling up is simple but has a hardware ceiling, rising cost and a single point of failure.
  • Scaling out adds stateless copies behind a load balancer and scales close to linearly.
  • Shared components, usually the database, end linear scaling; more app servers then do nothing.
  • Relieve the data tier with caching, read replicas and sharding, each with its own costs.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

Scalability is a system's ability to handle more load by adding resources, without being redesigned, at a cost that grows roughly in proportion to the load. "Load" can mean requests per second, data volume, number of users, or number of concurrent connections, and a system can scale well along one of these and badly along another. Scalability is not the same as speed: a fast system that cannot grow is not scalable, and a scalable system can be slow per request.

Why it exists

Load changes. Products grow, traffic follows daily and seasonal cycles, and a single event can multiply it in minutes. A system that can only grow by being rewritten forces a choice between turning users away and a risky migration under pressure. Designing for scalability means knowing in advance what you will add next when load grows, and what it will cost.

How it works

Vertical scaling (scale up) gives one machine more resources: CPU cores, memory, faster disks. The software does not change. It is the simplest and often the cheapest first step, but it has limits: there is a largest machine, prices rise steeply near the top of the range, upgrades often need a restart, and the machine remains a single point of failure.

Horizontal scaling (scale out) adds more machines running the same software, with a load balancer spreading requests across them. It has no fixed ceiling and adds redundancy, but requires that any server can handle any request. That means servers must be stateless: sessions, uploads and other state live in shared stores (databases, caches, object storage), not in a server's memory or local disk.

Linear and sublinear scaling. Stateless servers that share nothing scale almost linearly: twice the servers, twice the capacity. Real systems eventually share something: a database, a cache cluster, a lock, a third-party API. Once that shared component saturates, adding more of the scalable tier no longer helps, and can even make latency worse by adding to the shared component's queue. Coordination between nodes (locks, consensus, cross-node queries) also makes scaling sublinear.

Scaling the data tier is the hard part:

  • Caching removes repeated reads.
  • Read replicas copy the data so reads spread over several machines; writes still go to one primary, and replicas may lag.
  • Sharding (partitioning) splits the data across machines by a key, scaling writes and storage at the cost of cross-shard queries, rebalancing and operational complexity.
  • Changing the model: denormalising, precomputing results, or moving some data to a store designed for that access pattern.

Elasticity is scalability over time: adding and removing capacity automatically as load changes (autoscaling), so you pay for peak capacity only during peaks.

When to use it

Plan for scalability when growth is expected or load is spiky, when the cost of being unable to grow is high, and especially for decisions that are expensive to change later: the data model, the partitioning key, and whether servers hold state. Keep stateless tiers stateless from the start; it costs little and enables both scaling and redundancy.

When not to

Do not build for a hundred times your current load when you have no evidence you will reach it. Sharding, multi-region deployments and service splits slow down development and add failure modes. A single well-sized server and a managed database scale surprisingly far; scale up first, scale out stateless tiers when you need more capacity or redundancy, and tackle the data tier when measurements show it is the limit.

Trade-offs

Approach You gain You pay
Scale up No code changes, simple operations Hardware ceiling, rising cost, single point of failure, upgrade downtime
Scale out stateless servers Near-linear capacity, redundancy Load balancer, deployment and monitoring of many instances, state moved elsewhere
Caching Large drop in database load Staleness and invalidation
Read replicas Read capacity, availability Replication lag, read-your-writes problems
Sharding Write and storage capacity Cross-shard queries, rebalancing, much more operational work
Autoscaling Pay for what you use, absorb peaks Scale-up lag, cold starts, needs good metrics

Alternatives

When a component cannot scale further or it is too costly, change the workload instead: process work asynchronously through queues at a sustainable rate, rate-limit or shed low-priority traffic, precompute expensive results, move static content to a CDN, or degrade optional features under load.

Failure modes

  • Scaling the wrong tier: more app servers in front of a saturated database.
  • Hidden state: in-memory sessions or local files that break when requests land on another server.
  • Hot spots: one shard, cache key or partition receives far more traffic than the rest, so adding nodes does not help.
  • Coordination overhead: global locks or cross-node transactions that grow with the number of nodes.
  • Autoscaling too late: new instances take minutes to start while the existing ones are already overloaded.
  • Connection limits: every new app server opens more database connections until the database runs out.

In production

Load-test to know each tier's capacity and which tier saturates first. Keep application servers stateless and run them behind managed load balancers with autoscaling on a metric that reflects saturation (CPU, request concurrency or queue depth). Use connection pooling or a proxy in front of the database so app servers do not overwhelm it. Watch the shared components (database, cache, message broker) most closely, because they are where linear scaling ends. Plan the next scaling step before it is needed.

Common misconceptions

  • "Microservices make a system scalable." They let parts scale independently, but each service still has its own data-tier limits, and the network calls add overhead.
  • "More servers always means more capacity." Only while the servers are the bottleneck.
  • "Vertical scaling is outdated." Modern machines are very large; scaling up is often the most cost-effective move for databases in particular.
  • "Scalability and performance are the same." Performance is how fast one request is; scalability is how capacity grows with resources.

Interview angle

Start with a single server and estimates, then grow the design as the numbers require: scale up, put stateless app servers behind a load balancer, add caching, then replicas, then sharding with a clear partitioning key. At each step say what limit you are removing and what it costs. Interviewers listen for statelessness, for recognising the database as the usual bottleneck, and for awareness of hot spots and connection limits.

Model assumptions

The simulation is a simplified model, not a benchmark. The first server has 4 workers; the "large" server and each later copy have 16, all with a 50 ms mean service time (lognormal, cv 0.3), so capacity grows exactly with workers; real machines do not scale perfectly with size. A worker waiting for the database stays busy. The database has 4 connections and an 8 ms mean query time (about 500 queries per second). The cache answers a fixed 70% of lookups. The load balancer uses least connections and adds no capacity limit of its own. Arrivals are random (Poisson). Numbers show behaviour and orders of magnitude only.

The lesson as textEvery step of the simulation, written out.
  1. 1. Scalability is about growth

    A system is scalable if it can handle more load by adding resources, without being redesigned, and without each extra request costing more than the last.

    Today one small server handles 40 requests per second and is about half busy. It can do about 80. The question this lesson asks: what happens at 10× the traffic?

    Scene: Users send 40 requests per second to one small app server, which is about half busy. Every request succeeds.

    Key idea: Scalability is the ability to grow capacity by adding resources, roughly in proportion to the load.

  2. 2. Traffic outgrows the server

    Traffic triples to 120 requests per second. The server can still finish only about 80; the rest wait, then get rejected.

    There are two ways to add capacity: make this machine bigger (scale up) or add more machines (scale out).

    Scene: At 120 requests per second the server completes only about 80 per second; it is fully busy and rejects the rest.

    Key idea: Every machine has a capacity; past it, you must add resources or turn requests away.

  3. 3. Scale up: a bigger machine

    We move the app to a machine four times the size: 16 workers instead of 4. Nothing else changes: same code, same single server, no load balancer.

    Capacity rises to about 320 per second and the server is now well under half busy. Scaling up is the simplest first move and often the right one.

    Scene: The app runs on a larger machine with 16 workers. It completes all 120 requests per second and is well under half busy.

    Key idea: Vertical scaling (scale up) adds CPU, memory or workers to one machine: simple, no code changes.

  4. 4. Even the big machine runs out

    Traffic grows to 400 requests per second. The large server tops out at about 320 and starts rejecting again.

    Scaling up has a ceiling: there is a largest machine you can buy, the price per unit of capacity rises near the top, and upgrading usually means downtime. It is also still one machine: when it fails, everything fails.

    Scene: At 400 requests per second even the large server is saturated: it completes about 320 per second and rejects the rest.

    Key idea: Vertical scaling hits a hardware ceiling, gets expensive near the top and keeps a single point of failure.

  5. 5. Scale out: more machines

    Instead of a bigger machine, we run three copies behind a load balancer. Each gets a third of the traffic and is well under half busy; the errors stop.

    This works because the servers are stateless: they keep no user data between requests, so any server can answer any request. Sessions and data live elsewhere.

    Scene: A load balancer spreads 400 requests per second over three identical app servers. Each is well under half busy and nothing fails.

    Key idea: Horizontal scaling (scale out) adds identical stateless servers behind a load balancer.

  6. 6. Capacity that grows with servers

    Traffic grows to 600 requests per second. Each server still gets an equal share, about 200, and nothing fails. Three servers carry about three times what one could, because they share nothing with each other.

    That is linear scaling: double the servers, double the capacity. Need more? Add a fourth. With an autoscaler, the number of servers can even follow the traffic.

    Scene: At 600 requests per second each of the three servers handles about 200 per second; all are moderately busy and nothing fails.

    Key idea: Servers that share nothing scale linearly: N servers give about N times the capacity.

  7. 7. Everything meets at the database

    Real requests need data. Every server now queries one database that can run about 500 queries per second, less than the 600 requests arriving.

    The database saturates, app workers sit waiting for it and fill up, and requests are rejected. Throughput is stuck near the database’s 500: the servers still share something after all.

    Scene: All three app servers query one database. The database is fully busy, the app servers fill up waiting for it, and throughput stays near 500 per second while the rest is rejected.

    Key idea: A shared component (often the database) ends linear scaling: the stateless tier scales, the shared one does not.

  8. 8. A fourth server changes nothing

    The reflex is to add another app server. App 4 joins the pool, and throughput… stays where it was. The new server just adds more queries to the same saturated database, and latency even gets worse because more requests queue for it.

    When scaling one tier stops helping, the bottleneck is somewhere else. Measure before buying.

    Scene: A fourth app server joins. Throughput stays near 500 per second because every server still waits for the same saturated database.

    Key idea: Adding capacity anywhere except the bottleneck is wasted.

  9. 9. Take load off the shared part

    The data tier is the hardest to scale, so first send it less work. A cache answers 70% of reads, and the database now sees under a third of the traffic.

    Throughput reaches the full 600 and errors stop. When caching is not enough, the next tools are read replicas (copies that serve reads) and sharding (splitting data across databases), each with consistency costs of its own.

    Scene: A cache answers 70% of reads. The database is no longer saturated, all 600 requests per second complete and nothing is rejected.

    Key idea: Scale the shared tier by reducing its load (caching), copying it (replicas) or splitting it (sharding).

  10. 10. What scaling costs

    Scale up first while it is cheap; scale out stateless tiers when you need more or need redundancy; then attack the shared parts. Each step adds something to run: a load balancer, more servers to deploy and monitor, a cache to keep consistent, eventually replicas and shards.

    Scalability is not one feature but a property of the whole design. The goal is a system where you know what to add next, and roughly what it will cost, before the traffic arrives.

    Scene: The final design: a load balancer, four stateless app servers, a cache and a database, serving 600 requests per second without errors.

    Key idea: Scaling trades simplicity for capacity: plan the next step before you need it, and scale only what is the bottleneck.