Part 01 · Thinking About Scale
What Scaling Really Means
The shop goes from 1K to 1M daily users. What actually breaks as it grows, and why "just add more servers" is not a plan.
⏱ 9 min · Station 2 of 93
The problem
The shop runs on one server with one PostgreSQL. Today it has about 1,000 daily users and nobody complains. The plan says 100,000 users next year and 1,000,000 the year after, and every Eid sale pushes traffic 20 times higher for a few hours.
The first instinct is "when it gets slow, we'll add servers". Before we add anything, we need to know three things: how much traffic the shop handles now, what happens when traffic goes past that, and which part gives up first. Today's lesson answers the first two with a measurement.
The idea
Load is how much work arrives: requests per second, mostly. Capacity is how much work the system can finish per second while staying fast enough. A system is scalable if, when load grows, you can add resources and keep latency within your target, at a cost that makes sense.
Two things make this harder than it sounds:
- Daily users is not the number that breaks servers. Requests per second at the busiest minute is. 1,000,000 daily users who each open 20 pages is about 230 requests per second on average, but evenings, paydays and Eid make the peak several times higher.
- Systems don't slow down gently. Below capacity, latency barely moves. Past capacity, requests start waiting in line, and latency goes from milliseconds to seconds in one small step. That step is the breaking point, and it is the most important number you can know about your system.
How it works
- Every request uses resources: CPU time on the app server, CPU and disk on the database, a database connection, network. Each of them can do only so much per second.
- While arrivals are below every resource's limit, each request finds what it needs free. Latency is just the time the work takes: our product page needs 2 to 6 ms.
- The first resource to hit its limit is the bottleneck. In our shop that's the database's CPU (it has one CPU thread of its own), because the "customers also bought" query scans 20,000 products on every page view.
- When arrivals exceed the bottleneck's capacity, the extra requests wait. The line grows every second by the difference between what arrives and what gets done: at 600 requests per second against a capacity of about 560, 40 more requests join the line every second.
- Latency now includes the wait in line, which grows for as long as the overload lasts. Users see seconds, then timeouts.
- Throughput can even drop. Waiting requests hold connections and memory, and the server spends effort juggling them, so it finishes fewer requests than it did at its best.
The shop handles 500 requests per second with p95 at 17 ms. You send 600 requests per second (20% more). What happens to p95?
Visual
The same run as a picture of where the requests go:
below capacity (500/s) past capacity (600/s)
arrive 500/s ──► [ db: 1 CPU ] ──► 500/s arrive 600/s ──► [ queue ▓▓▓▓▓▓▓▓ ] ──► [ db: 1 CPU ] ──► ~560/s
p95 17 ms grows ~40/s p95 0.7 s
The queue in front of the database is where the seconds come from.
Common misconception
"When it gets slow, just add more servers." More of what? Our bottleneck is the database's CPU. Three more app servers would send the same queries to the same database and break at the same 560 requests per second, with a bigger bill. Adding resources only helps at the bottleneck, so you have to find it first (that's two lessons from now).
A second one: "We have 1 million users, so we need a big system." A million daily users can be a few hundred requests per second, which one well-tuned server handles. The numbers that matter are peak requests per second, how much data, and how much of it is writes.
Try it
Measured on an Intel i3-10110U laptop (4 threads), 7 GB RAM, Ubuntu 26.04, Docker 29.8; the shop and PostgreSQL each pinned to one CPU thread. Your numbers will be different; the shape won't.
ramp.sh (in the lab folder) runs product.js at several rates for 20 seconds each and prints one row per rate:
#!/bin/sh
# Run one k6 script at several rates, one table row per rate.
# ./ramp.sh product.js "25 50 100 150 200" 20s [extra k6 args]
script=$1; rates=$2; dur=${3:-20s}; shift 3
echo " rate got/s p50 p95 p99 failed dropped"
for r in $rates; do
./k6.sh "$script" -e LINE=1 -e RATE="$r" -e DURATION="$dur" "$@" 2>/dev/null
sleep 3
done
We warm PostgreSQL's cache with 30 seconds of traffic first, then ramp:
rate got/s p50 p95 p99 failed dropped
100 100 3.2 ms 5.9 ms 7.6 ms 0.0% 0
200 200 2.1 ms 5.0 ms 7.5 ms 0.0% 0
300 300 1.9 ms 4.0 ms 6.3 ms 0.0% 0
400 400 1.9 ms 5.6 ms 12 ms 0.0% 0
500 500 2.3 ms 17 ms 34 ms 0.0% 0
550 550 8.5 ms 55 ms 71 ms 0.0% 0
600 562 393 ms 697 ms 741 ms 0.0% 400
700 561 863 ms 926 ms 968 ms 0.0% 2337
Reading it:
- 100 to 500 requests per second: everything gets through (
got/sequalsrate), p95 at or under 17 ms, no drops. Up to 400, p95 even gets a little lower as load rises: a busier CPU stays at full clock speed and its caches stay warm. - 550: the bend. Everything still gets through, but p95 has tripled to 55 ms. Requests have started to wait for each other.
- 600: the cliff. k6 asked for 600 per second and only 562 got through. p95 is 0.7 seconds, and 400 requests were dropped because all 500 of k6's virtual users were stuck waiting.
- 700: no better. Still about 560 per second completed. Asking harder doesn't get more done; it only makes the line longer. (Latency stops near one second only because k6 runs out of virtual users. Real users would keep arriving and the wait would keep growing.)
| Rate asked | Got through | p95 | What it means |
|---|---|---|---|
| 500/s | 500/s | 17 ms | room to spare |
| 550/s | 550/s | 55 ms | near the edge: requests start waiting |
| 600/s | 562/s | 0.7 s | past capacity: queueing |
| 700/s | 561/s | 0.9 s | still broken, nothing more gets done |
So the single-server shop's capacity is somewhere between 550 and 600 requests per second. What does that mean in users? If the busiest minute is 4 times the daily average and each user opens 20 pages a day, 550 requests per second at peak is about 600,000 daily users. Plenty for next year's 100,000. Not enough for the year after: 1,000,000 users peak near 930 requests per second. And an Eid sale at 20 times a normal day is far beyond it.
Trade-offs
- Measuring capacity costs time, and guessing costs more. One ramp test takes a few minutes. Without it, you learn your breaking point from users during a sale.
- Capacity is per workload. Our 560 requests per second is for random product pages. A checkout or a search has a different number. Test the mix your users really send (the Reliability course goes deep on realistic tests).
- Headroom is not waste. Running close to the cliff saves money until a small spike pushes you over it. Most teams aim to use well under their breaking point at peak.
- Don't scale before you need to. Every component this course adds (load balancers, caches, replicas, queues, shards) brings cost and new ways to fail. The goal is to add each one when a measured bottleneck asks for it, not before.
Key takeaway
Scaling starts with a number: the request rate at which your system stops being fast. Below it latency barely moves; past it requests queue and latency jumps to seconds while throughput drops. Find that number, find what limits it, and only then add resources there.
Practice
Objective: find the shop's breaking point more precisely.
Challenge: our run showed the cliff somewhere between 550 and 600 requests per second. Predict where exactly, then run the ramp at 500, 525, 550, 575 and 600.
Expected result: a table where you can point at the last rate that got fully through with a low p95, and the first one that didn't.
Hint 1
The breaking point is where got/s stops matching rate and dropped becomes non-zero.
Hint 2
./ramp.sh product.js "500 525 550 575 600" 20s from the lab folder. Warm the cache first with one run at 80 requests per second.
Hint 3
Run it twice. Near the edge, a run can go either way: background activity on your laptop shifts the cliff by a few requests per second.
Solution
Our run:
rate got/s p50 p95 p99 failed dropped
500 500 2.4 ms 17 ms 34 ms 0.0% 0
525 525 2.5 ms 22 ms 36 ms 0.0% 0
550 550 11 ms 44 ms 56 ms 0.0% 0
575 560 174 ms 314 ms 334 ms 0.0% 144
600 545 433 ms 913 ms 939 ms 0.0% 652
Up to 550 requests per second everything got through, but p95 climbed from 17 to 44 ms on the way: the queue was already forming. At 575, only 560 got through, p95 jumped to 314 ms and 144 requests were dropped. So this setup's capacity is about 560 requests per second, and it starts to degrade before it breaks. A 5% step past 550 was enough to go from fine to broken, which is why you never plan to run at your measured maximum.
Interview check
Q: Your service handles 150 requests per second today with low latency. Marketing expects 300 next month. What do you do first?
Model answer
Measure before changing anything: run a ramp test to find the real breaking point and look at which resource saturates first (CPU, database, connections). Then estimate the real peak: 300 per second average might be a much higher peak. Only then decide: fix the bottleneck (an index, a cache), scale that specific resource, or both, and re-run the same test to prove the new capacity is above the expected peak with headroom.
Q: Why does throughput sometimes go down when you send more traffic than the system can handle?
Model answer
Past capacity, requests pile up waiting. They hold connections, memory and threads, timeouts fire and some work is done for clients who already left, and the server spends effort switching between many waiting requests. The useful work per second (goodput) drops below the clean maximum, so pushing harder makes it worse. That's why systems need to reject excess load early instead of accepting everything.
Station stamp
Finish the chapter
Done reading? Press Complete to save your progress. XP is Pro-only — on Pro this chapter is worth +10 XP.
Go Pro to earn XP →