Course contents · Lesson 10 of 19

Capacity Planning Basics: Will It Hold on Sale Day?

Scaling and Capacity · Lesson 10 of 19 · 10 min Engineer

Your shop's yearly sale starts at 10 a.m. on Friday, when the marketing email reaches every customer at once. Will checkout hold, or time out at the worst moment? Answering that in advance is capacity planning: estimating how much computing a service will need, and having it ready before the demand arrives. This lesson works through the numbers.

Know your current numbers

Start from measurements, not hunches. You need three numbers, and your monitoring's metrics, numbers stored over time, provide most of them:

  • Peak requests per second (req/s): the highest request rate, measured over a short window such as one minute at the busiest time. Plan for the peak, not the average: 3 million requests a day averages about 35 per second, but if most arrive in the evening, the busiest minute runs several times higher.
  • Resource use at peak: how busy CPU, memory, disk, network and database connections are, each as a share of what is available, called utilisation. The first to run out is the bottleneck, and it sets your limit.
  • How much one server can safely handle: the highest rate at which a server still meets the latency and error SLOs from lesson 4. Past it, requests queue inside the server and latency climbs steeply, often well before CPU reads 100 percent. Your busiest days give a first estimate, and a load test measures it.

Forecast demand: growth, events and a safety multiple

A forecast is your best estimate of future demand. Google's SRE book separates organic growth, the steady rise as more people use the product, from inorganic growth, jumps caused by events such as launches and marketing campaigns. A sale-day forecast combines three parts:

  • Organic growth: how the peak grew over past months, extended forward.
  • Planned events: sale days, launches, a TV advert, which the trend cannot show. Compare last year's event with a normal day, and ask the people planning this one.
  • A safety multiple: an extra factor, such as 1.25, for the unknown, like a sale that goes viral.

With illustrative numbers: today's normal peak is 360 req/s, growing about 10 percent a quarter, so expect about 400 by the sale. Last year's sale peaked at twice a normal day, giving 800. The safety multiple of 1.25 turns that into a planning figure of 1,000 req/s.

In the chart, notice two gaps above the demand line: a small one on sale day, which is your headroom, and a large one on every other day, which you pay for without using.

Illustrative line chart of requests per second over the 12 weeks of a quarter. Capacity is a flat line at 1,500 requests per second, 10 servers of 150 each. The daily peak grows slowly from 360 to 400, organic growth. In week 9, sale day, the forecast spikes to twice normal, 800, and a safety multiple of 1.25 raises the planning figure to 1,000. The gap from 1,000 up to capacity is marked headroom: 500 requests per second, 33 percent. On ordinary days the much larger gap is marked idle: only about 25 percent is in use, but all of it is paid for
Capacity is sized for the spike, so on ordinary days most of it sits idle.

Add headroom and survive one failure

As lesson 7 showed, headroom is spare capacity kept free so a service copes with surprises while more arrives. Say you plan to use at most 70 percent of each server's safe limit, keeping 30 percent spare. The diagram turns that into a server count and checks it against a failure.

Step-by-step calculation with illustrative numbers. Three inputs: an expected peak of 1,000 requests per second, a safe limit of 150 per server, and 30 percent headroom, so each server uses only 70 percent. Combined: 1,000 divided by 150 times 0.7 is 9.52, since each server may use 105 requests per second. Rounded up, provision 10 servers. The N+1 check: lose one and 9 are left, and 9 times 150 is 1,350 requests per second, above the 1,000 peak. A footer warns never to round down, because 9 servers leave only 26 percent headroom
Divide by what one server may use, round up, then check the fleet still holds with one server gone.

Always round up: with 9 servers, each would run at 74 percent of its limit, past the target.

The second check is N+1: if N servers can carry the peak, run at least one more, so the service survives losing any one of them to a crash or an update. Here N is 7, because 1,000 ÷ 150 is 6.7, rounded up, and the plan has 10. Losing one leaves 9 × 150 = 1,350 req/s, so the headroom already covers it.

N+1 matters most for small fleets. With an illustrative peak of 200 req/s, the headroom rule gives 200 ÷ 105 = 1.9, so 2 servers. Lose one and the survivor faces 200 req/s against a safe limit of 150. N is 2 here, so N+1 means 3 servers.

The count covers only the app servers. Shared parts do not grow with them: every order still writes to one database primary (lesson 7), and if the cache from lesson 8 fails or starts empty, the database takes the full load. Size each shared part the same way.

Validate with a load test, and mind lead times

A load test sends artificial traffic at a controlled, rising rate to a copy of the service while you watch latency and errors. It turns an estimate such as 150 req/s into a measurement, and often finds an unexpected bottleneck, such as a database connection limit.

Run it in steps, for example 10 minutes each at 50, 100, 150 and 200 req/s, against a copy built like production with realistic data, and include a run with an empty cache. The safe limit is the highest step that still meets your SLOs. Tools such as Grafana k6, Locust and Apache JMeter generate the traffic; use them only on systems you own.

Lead time is how long capacity takes to arrive after you decide you need it. Physical servers can take weeks or months to order, deliver and install. In the cloud, each account has quotas, limits on how much of a resource it may run. Raising one is a request that may be approved in minutes or take days, and a region can run short of a popular machine type.

So your forecast must look further ahead than your longest lead time, a step Google's SRE book calls mandatory. For a sale six weeks away, request quota increases now; many providers also let you reserve capacity in advance. Then provision the servers, meaning set them up ready for traffic, before the day. Autoscaling still helps on the day, but only up to its configured maximum and your quota.

Make it a routine

Traffic, code and prices keep changing, so capacity planning is a loop, not a project. In the flowchart, notice the dashed arrow back to the start: each review feeds fresh measurements into the next plan.

Flowchart of six steps in a loop. 1, measure: peak, resource use and one server's safe limit. 2, forecast: growth plus events, times a safety multiple. 3, add headroom: 30 percent spare, plus N+1. 4, load test: prove the safe limit. 5, provision: order ahead of the lead time. 6, review: compare the forecast with real use, and check cost. A dashed arrow labelled next quarter leads from review back to measure, and the centre reads every quarter, or before a big event. A footer warns to start early: hardware takes weeks, and quota increases can take days
The review is what makes the next forecast better than this one.

Each quarter, compare the forecast with what really happened. If the peak beat the forecast by 30 percent, find out why: a missed event, a popular new feature, or slower code that lowered the per-server limit.

Review cost too: capacity only about 25 percent used on normal days, as in the chart, is mostly money spent on nothing. Remove the extra servers after the sale, or let autoscaling shrink the fleet between peaks; Cloud Cost Basics explains the bill.

Check yourself

Your service averages 40 req/s across a day, and one server safely handles 150. Why is one server still not enough?

The average hides the peak, which can be several times higher, and one server has no spare: a single crash or update takes the service down. Size from the peak, then add headroom and N+1.

You double the app servers, but the load test still fails at the same rate. What does that tell you?

The bottleneck is not the app servers but something shared that did not grow, such as the database or its connection limit. More servers only help when servers are the limit.

The sale is three weeks away and your plan needs twice your current cloud quota. Why ask today rather than in sale week?

Quota increases and reserved capacity have lead times, possibly days, and a region can run short of machines. A request made too late leaves you with a plan but not the servers.

Go deeper