Fundamentals
Scaling fundamentals
Vertical versus horizontal scaling, stateless services, the usual order in which a growing system adds parts, and how to find the real bottleneck. Start here for the scaling map.
A system scales if you can add capacity by adding resources, roughly in proportion. Double the servers, and you roughly double the requests you can serve. Systems that do not scale hit a wall. Adding machines does nothing, or makes things worse, because a shared component, usually the database, is already saturated.
Most real systems do not start distributed. They start as one process on one machine. They add parts one at a time, as specific bottlenecks appear: a separate database, a load balancer, a cache, replicas, a CDN, queues, shards, more regions. Knowing that order, and why each step comes when it does, is most of what scaling means in practice.
Three words that get mixed up
- Performance is how fast one request is served at a given load.
- Scalability is how capacity grows as you add resources.
- Elasticity is how quickly and cheaply capacity follows demand, both up and down.
A system can be fast but not scalable. A single big in-memory server is one example. It can also be scalable but slow, such as a batch pipeline that takes an hour but handles ten times more data with ten times the workers. A useful test is: "If traffic tripled tomorrow, what would we do, and how long would it take?" The answer reveals all three properties at once.
Concepts in this topic
Read them in order. Each one builds on the last.
| Step | Concept | What it answers |
|---|---|---|
| 1 | Vertical versus horizontal scaling | Do you buy a bigger machine or add more of them? |
| 2 | Stateless services | What must move out of a process before you can add copies? |
| 3 | The canonical scaling path | Which part of a growing web app breaks first, and what do you add? |
| 4 | The scale cube | What are the three independent ways to split a system? |
| 5 | Finding the bottleneck | Which resource is saturated, and how much will a fix help? |
| 6 | Growing a marketplace | What does a plan look like with real numbers? |
Common mistakes
- Scaling before measuring. Adding a queue or a shard before finding the saturated resource moves the problem.
- Choosing infrastructure for big-company reasons. Each component needs to be justified by a number.
- Underestimating the cost of distribution. Sharding, microservices and multi-region each bring operations work. A sharded database needs routing, cross-shard queries and resharding tools, which can take months.
- Forgetting that the database is the usual limit. The app tier is stateless and cheap to copy. The database is shared and stateful.
Key takeaways
- Scalability, performance and elasticity are different properties, so measure the one you need.
- Scale up first. Modern machines are large, and a single big database goes a long way.
- Horizontal scaling requires statelessness, with sessions, files and queues moved out of the process.
- Take each step only when a measured bottleneck demands it, and write down the next step.
- Keep peak utilization around 50 to 70%, because latency rises sharply as utilization nears 100%.
Further learning
Dan McKinley's essay "Choose Boring Technology" argues that each team has a small budget of unfamiliar technology. Spend it where it differentiates your product, and use well-understood tools everywhere else:
Choose Boring Technology (Dan McKinley)Choose Boring TechnologyDan McKinley :: Math, Programming, and Minority Reports
Martin Kleppmann's book covers the replication, partitioning and consistency trade-offs that appear once a system outgrows one machine:
Designing Data-Intensive Applications (Kleppmann)Designing Data-Intensive Applications (DDIA) — an O’Reilly book by Martin Kleppmann (The Wild Boar Book)dataintensive.netStart with vertical versus horizontal scaling to see the first choice in this topic.
Related
Vertical versus horizontal scaling
Scaling up with a bigger machine versus scaling out with more machines, what each costs, and when scaling up stops being the right answer.
Stateless services
A stateless service can handle any request on any instance. Learn where the state goes instead, and the login bug that appears when a service keeps sessions in memory.
The canonical scaling path
The usual sequence in which a successful web app adds parts, from one server to queues, shards and regions, with the symptom that triggers each step.
Back-of-the-envelope estimates
Turn users and features into QPS, storage and bandwidth numbers in two minutes, and use them to decide what the design actually needs.
Load balancing and proxies
How a load balancer chooses which server gets each request, and how a badly set up balancer can cause the outage it was meant to prevent.
Sharding and partitioning
Split data across machines by choosing a shard key, hashing or ranging it, routing requests, handling hot spots, resharding without downtime and generating IDs that stay unique.