Advanced System Design Fundamentals
Vote

0% completed

​

Capacity Planning

Part 1: From an Estimate to a Fleet

Part 2: Size for the Peak, Not the Average

Part 3: Plan for Growth

Part 4: Headroom, Because a Full Server Is Too Full

Part 5: Losing a Zone

Part 6: Why the Fleet Is Bigger Than the Arithmetic

Part 7: Autoscaling Does Not Remove the Plan

Part 8: Using This in an Interview

Common Mistakes

Key Takeaways

An estimate says a service gets 1,000 requests a second, and a load test shows that one server can serve 500. The service therefore needs two servers. That arithmetic is correct, and a fleet built from it would fail on its first busy evening.

This lesson covers the steps from that arithmetic to a working fleet: the peak, growth, headroom, the loss of a zone, and the rounding that real machines force.

Part 1: From an Estimate to a Fleet

The running example is the product-page API of a large online store, with 100 million requests a day. With a day rounded up to 100,000 seconds, the average is about 1,000 requests a second. A load test sends rising traffic to one server. The store's load test finds that one server can serve at most 500 requests a second. All numbers in this lesson are made-up examples.

Two terms describe the work:

  • Capacity planning decides how many machines a system needs, and by when. Its input is an estimate of load.
  • A fleet is the group of machines that runs one service. It is the output of capacity planning.

Back-of-the-Envelope, Revisited showed that a server count rarely changes the design. It does decide the bill, and whether the service survives its busiest hour. The diagram below shows the five steps from the store's average to a fleet, with the server count after each one.

Five steps from an average request rate to a fleet size, where the server count grows from 2 to 15
Five steps from an average request rate to a fleet size, where the server count grows from 2 to 15

Notice the last column of the diagram, where the count goes from 2 to 6, 7.2, 9 and finally 15. No step is large on its own. The fleet grows because the steps multiply. Parts 2 to 5 explain each step in order, and Part 6 covers the rounding that real machines add.

Part 2: Size for the Peak, Not the Average

The first step in the diagram replaces the daily average with the peak. The peak-to-average ratio is the busiest rate divided by the average rate. For many consumer products, the busiest hours run at two to four times the daily average. That peak is a window a few hours wide, such as the evening.

With a ratio of three, the store peaks at 3,000 requests a second. At 500 requests per server, that needs six servers, not two.

The daily evening peak is only one shape of traffic. The table below lists four common traffic shapes, with made-up sizes.

ShapeTypical sizeHow much warning
Daily cycle2 to 4 times the daily average, for a few hoursSeen every day
Weekly cycleSome days busier than othersSeen every week
Seasonal peakUp to about 10 times an ordinary day, such as a yearly saleMonths
Event spikeSharp rises within minutes, such as a news storyLittle or none

Notice the last column. A spike can be sharper than a seasonal peak, but the seasonal peak is on a calendar, and the team knows about it months ahead. If the store fails during its yearly sale, that is a planning failure, not bad luck.

Part 3: Plan for Growth

The peak from Part 2 is today's peak. A fleet is sized for a period of time, and traffic grows during it. A growth multiplier is the factor by which load will rise before you can next add capacity.

The store's plan covers six months, with about 20 percent growth over that time. The peak therefore becomes 3,600 requests a second, or 7.2 servers.

How far ahead to plan depends on how fast new capacity arrives. A stateless API keeps no data of its own between requests, so it can get a new server in minutes. A larger database or ordered hardware can take months, so its plan must look further ahead.

Part 4: Headroom, Because a Full Server Is Too Full

The count of 7.2 servers from Part 3 assumes each server runs at its full limit of 500 requests a second. Utilization is the fraction of time a server is busy. At 100 percent, the arithmetic looks efficient, but in practice the server is already failing.

The reason is the queue. Requests arrive unevenly, and a request that arrives while the server is busy waits in line. Waiting time climbs sharply near full use. The diagram below shows this for the simplest textbook model of a queue.

Average waiting time at four levels of utilization, where the wait grows slowly at first and then very fast near full use
Average waiting time at four levels of utilization, where the wait grows slowly at first and then very fast near full use

Notice that the diagram measures each wait in units of the time to serve one request. At 50 percent busy, a request waits, on average, about as long as it takes to serve one request. At 80 percent, it waits about four times as long. At 90 percent, it is about nine times, and at 95 percent, about nineteen.

Real servers with many cores bend later, but they still bend sharply near the top. For this reason, the last part of a server's capacity cannot be used without long waits.

Headroom is capacity kept free on purpose, so the system stays fast. It is a requirement, not waste, because without it, requests face the long waits shown near the top of the diagram. Assume no store server should run above 80 percent of its limit, even on the worst normal day. Each server then takes 400 requests a second, so 3,600 requests need 9 servers.

Part 5: Losing a Zone

The 9 servers from Part 4 are enough only while every server is running. An availability zone is one or more separate data centers inside one cloud region, with their own power and network. With three zones, a fire or power failure in one does not take down the whole service.

However, if one zone fails, its users do not go away. The load balancer sends their traffic to the two zones that remain. The diagram below shows the store's fleet before and after a zone fails.

Fifteen servers across three zones before and after one zone fails, where each surviving server takes half again as much traffic
Fifteen servers across three zones before and after one zone fails, where each surviving server takes half again as much traffic

The 9 servers must still exist after a zone is lost, so each of the two remaining zones needs 4.5. Servers come whole, so each zone gets 5, and the fleet has 15.

Step 1: Normal peak. 3,600 requests a second across 15 servers is 240 each, or 48 percent of the limit.

Step 2: One zone fails. The same 3,600 now land on 10 servers. That is 360 each, or 72 percent.

Step 3: Check the limit. 72 percent is below the 80 percent target from Part 4, so the plan holds.

Notice the two rows for Zone A in the diagram: 240 each before the failure and 360 each after. Each surviving server carries 50 percent more than before, so normal utilization must leave room for that increase. That is why the fleet runs below half its limit on a normal busy evening.

Part 6: Why the Fleet Is Bigger Than the Arithmetic

The store's plan already rounded once, from 4.5 servers per zone up to 5. Real machines force more rounding than that. Three effects push the real fleet above the estimate, and all three round upward.

  • Whole machines. An estimate of 3.7 servers means 4. Spread evenly across three zones, 4 becomes 6.
  • Coarse sizes. Cloud machines come in fixed sizes, which often double from one size to the next. A service that needs 10 cores may have to buy 16.
  • Packing. Bin-packing is the problem of fitting items of different sizes into boxes, here workloads into machines. Workloads that need different resources rarely fill each machine evenly.

On a fleet of 400 servers, rounding up adds little. On a fleet of 4, each effect is a large share of the total.

Packing hides a further trap. Suppose a store server keeps popular products in memory, and it reaches its memory limit while its CPU is only 20 percent busy. That server is full. Its free CPU is stranded: free, but unusable, because there is no memory for more work.

A dashboard of average fleet CPU would show 20 percent and look idle. The binding resource is the one that runs out first, here memory. Free CPU cannot make up for missing memory, so an average that blends them misleads. Check each resource on its own.

Part 7: Autoscaling Does Not Remove the Plan

Parts 2 to 6 sized a fixed fleet. Autoscaling changes the size while the service runs: it adds servers when load rises and removes them when it falls. It saves real money on a daily cycle, because the store's fleet can shrink overnight.

However, autoscaling reacts more slowly than traffic can arrive. The system must notice the rise, start a machine, start the program, and load popular data into memory. Then the new server must pass a health check before it gets traffic. This takes from tens of seconds to several minutes, and the servers already running carry the whole rise meanwhile.

The fleet's floor is the smallest size autoscaling allows. For this reason, the floor must cover the sudden part of a peak. Autoscaling handles the slow evening climb, and the floor handles the spike.

Part 8: Using This in an Interview

The steps in this lesson arrive at two different times in the round. The peak estimate belongs in minutes 7 to 10 of a 45-minute round. The fleet size usually comes later, in the failure and cost stretch from minute 38 to 42.

"Peak is about 3,000 requests a second, three times the average. With 20 percent growth, I'll plan for 3,600. One server serves about 500, and I want none above 80 percent, even with a zone down. That gives five servers in each of three zones."

Each number has a reason attached. That shows trade-off reasoning, one of Module 1's four signals.

Expect two follow-up questions. "Why not run the servers at 90 percent?" Waiting time climbs sharply near full use, and a zone loss adds half again to each survivor. "Can't autoscaling handle the sale?" The sale is known months ahead, so you scale before it. Autoscaling covers only the slow part of a rise.

Common Mistakes

Mistake 1: Sizing from the daily average. The fleet must serve the busiest hours, which often run at two to four times the average.

Mistake 2: Treating headroom as waste. Without headroom, waits grow long and the first lost zone becomes an outage.

Mistake 3: Reading one average utilization figure. A fleet can be full on memory while its CPU looks idle, because free CPU cannot make up for missing memory.

Key Takeaways

  • Each step of a capacity plan multiplies the last. Peak, growth, headroom, and zone loss together turned 2 servers into 15.
  • Size for the peak window, not the daily average. It often runs at two to four times the average for a few hours.
  • The last part of a server's capacity cannot be used without long waits. Waiting time climbs sharply near full use, so headroom is a requirement.
  • With three zones, the survivors of a zone loss carry half again as much. Normal utilization must leave room for that.
  • In a system design interview, state the peak, the per-server limit, the headroom target, and the zone count, and give a reason for each.

The next lesson, The Other Envelope: Cost Estimation, shows how to turn a fleet like this one into a cost per request and a cost line for each design option.

Reading Progress

0%


Vote for new content

On This Page

Part 1: From an Estimate to a Fleet

Part 2: Size for the Peak, Not the Average

Part 3: Plan for Growth

Part 4: Headroom, Because a Full Server Is Too Full

Part 5: Losing a Zone

Part 6: Why the Fleet Is Bigger Than the Arithmetic

Part 7: Autoscaling Does Not Remove the Plan

Part 8: Using This in an Interview

Common Mistakes

Key Takeaways