SevyDevy

Module 2 · Thinking in Numbers First · Lesson 7 of 35

Capacity estimation in system design: numbers before boxes

13 minFree System design course · Beginner to intermediateLesson 2.3By Saket Bhatnagar

Researched and drafted with AI, reviewed and edited by Saket Bhatnagar.

In short

  • Capacity estimation in system design is quick, rough arithmetic that tells you how much load a system must carry and store before you build it.
  • Size for the busiest few minutes, not the daily average. SeatJaldi’s noon rush is about 140 times its daily average.
  • Round hard, say every guess out loud, and let the biggest number pick the design.
Soon

Video lesson · coming soon

Capacity estimation in system design: numbers before boxes

Lala, your AI mentor, will walk you through this lesson in a short animated video. Until then, everything is here to read and try.

  1. 01 The average says we are fine
  2. 02 The caterer’s plate count
  3. 03 Fill the SeatJaldi worksheet
  4. 04 From people to servers
  5. 05 Storage is tiny, the peak is not
  6. 06 A bigger machine, or more machines?

Arjun Nair has spent the whole morning on the wrong problem. His notebook is full of disk and backup plans for the final’s bookings.

Meera Kulkarni asks him how much space those bookings need. Ten minutes later he is red in the face. One booking is about 1 KB, roughly a thousand letters of text. 40,000 seats at 1 KB each is 40,000 KB, which is 40 MB (1,000 KB make 1 MB). That fits on a phone.

“And how many taps a second at noon?” Meera asks. Her guess is 5 lakh people in the first 10 minutes, about 20 requests each: 1 crore requests. Arjun spreads them over a day: about 116 a second. “Our ₹1,200 server handles 200 a second,” he says. “We are fine.” Meera frowns. Fans do not come spread over a day.

What is capacity estimation in system design?

Capacity estimation is quick, rough arithmetic that tells you how much load a system must carry and store, before you draw any box. It gives four numbers: users, requests a second, storage and data sent.

The number to design for is the busiest short stretch, called the peak. For SeatJaldi it is the first 10 minutes after noon.

  • Rough numbers decide the design, and the peak, not the average, is the design.
  • Round hard: 116 becomes 100, and 86,400 becomes 1 lakh. A little off is fine; ten times off is not.
  • Say every guess out loud, so someone can check it.
  • Find the biggest number. That is the hard part.
Try it yourselfFill the SeatJaldi worksheetStep from users to servers. Notice which number is biggest and which is tiny.

You have seen this when a ticket site is fine all week, then shows a waiting page at noon on sale day. It was sized for a normal day.

An exam-results site is quick all year, then falls over a minute after results come out. Nearly every visitor arrived in the same few minutes.

A cab app in the 6 pm rain shows “no cabs nearby”. Far more people wanted a cab that hour than the fleet was planned for.

How to calculate QPS?

To calculate QPS, the number from lesson 6, divide the total requests by the seconds they arrive in. The hard part is picking the right seconds.

Spread 1 crore requests over a day and you get about 116 a second. Squeeze them into the 600 seconds after noon and you get about 16,700. Nandini’s 2,900 rotis are a trickle over a day, but about 48 a minute in a one-hour rush.

Numbers to keep in your head (10^5 means a 1 followed by five zeros)
QuantityExactRound it to
1 day86,400 seconds10^5 seconds
1 month of 30 days2,592,000 secondsabout 2.6 million
1 lakh100,00010^5
1 crore10,000,00010^7
1 KBabout 1,000 bytes10^3 bytes
1 MB1,000 KB10^6 bytes
1 TB1 million MB10^12 bytes

From people to servers

The chain from 5 lakh people to about 16,700 requests a second and about 84 servers. The storage branch is only about 40 MB.

Diagram connections:

  • 5 lakh people to 1 crore requests (x 20 each)
  • 1 crore requests to 16,700 a second (/ 600 seconds)
  • 16,700 a second to About 84 servers (/ 200)
  • One server: 200/s to About 84 servers (Capacity of one)
  • 1 crore requests to Storage: 40 MB (Few are bookings)
  • 5 lakh people: Meera’s guess for the first 10 minutes.
  • 1 crore requests: 5 lakh people x about 20 requests each.
  • 16,700 a second: The peak: 1 crore requests / 600 seconds.
  • One server: 200/s: Today’s server, about 200 a second.
  • About 84 servers: The peak divided by 200, rounded up.
  • Storage: 40 MB: 40,000 bookings at about 1 KB each.

How many servers do I need?

Divide the peak by what one server can take, then round up: 16,700 divided by 200 is about 84 servers. Round up, never down: you cannot rent 83.5 servers, and 83 would leave some requests with nowhere to go.

Nandini does the same with cooks. Say one cook rolls 20 rotis a minute and the rush needs 48. That is 2.4 cooks, so she books 3.

How do engineers add headroom and size workers?

Engineers add headroom, split reads from writes, and use Little's law to count the workers needed.

Headroom means building for more than the estimate. A common habit is 2x: 16,700 x 2 = 33,400 a second, and 33,400 / 200 = 167 servers. You gain room for a bad guess or a dead machine, at twice the cost. Nandini’s extra 20% of rotis is her headroom.

Google’s guide to running large systems works an example where a system still carries its peak with two groups of servers down. It also says to test each part until it breaks, which turns a guess like 200 a second into a measurement.

Little's law counts the workers, treating the 10-minute rush as steady. Assume each request takes 0.2 seconds and each worker holds one request at a time. A server at 200 a second has 200 x 0.2 = 40 requests in progress, so it needs about 40 workers. Check: each worker finishes 1 / 0.2 = 5 a second, and 40 x 5 = 200.

For the whole sale, 16,700 x 0.2 = 3,340 requests are in progress, and 3,340 / 40 = 83.5, about 84 servers. A slowdown eats capacity: at 0.4 seconds each, the same peak needs 167 servers, double, just as the doubling in lesson 6 showed.

A classic worked example: a link shortener

A link shortener turns a long web address into a short one.

Link shortener estimate (every input is an assumption)
NumberWorkingResult
Writes: 100 million links a month100,000,000 / 2,592,000 secondsabout 39, call it 40 a second
Reads: 100 per write40 x 100about 4,000 a second
Peak: 3x the average4,000 x 312,000 reads a second
Storage: 5 years, 500 bytes a link100 million x 12 x 5 = 6 billion links; x 500 bytes3 x 10^12 bytes = 3 TB
Data sent4,000 x 500 bytes, or 12,000 at the peakabout 2 MB a second, 6 MB at the peak

What just happened? Writes were tiny, reads 100 times bigger, and 3 TB fits on a few disks. Raw capacity was simple. The real design is availability: keeping it answering all day.

Try it yourself

  1. Write the guesses

    A concert has 10,000 seats. Assume 1 lakh people in the first 10 minutes, about 20 requests each.

  2. Find the peak

    Work out the total requests, then divide by 600 seconds.

  3. Find the storage

    Work out the space for 10,000 bookings at about 1 KB each.

  4. Count servers

    Divide the peak by 200 and round up. Then add 2x headroom the same way as the 167 above.

  5. Name the hard part

    Say which number is the hard part, and which guess to check first.

  6. Check your answer

    Total: 100,000 x 20 = 2,000,000. Peak: 2,000,000 / 600 = about 3,300 a second. Storage: 10,000 x 1 KB = about 10 MB. Servers: 3,300 / 200 = 16.5, so 17, or about 33 to 34 with 2x headroom. The hard part is the peak; check the 20 requests each first. You got it right if you have about 3,300 a second, about 10 MB and about 17 servers.

Arjun tears up his disk plans. Storage was never the hard part. The peak was: about 16,700 requests a second, against 200 on one server.

“Will it hold at noon?” Meera asks. “Not on one server,” Arjun says. “We need about 84 like it.” Meera shakes her head. “I cannot rent 84 of anything.” Arjun has an idea: buy one huge server instead. Meera does not look sure.

Like Nandini, they have their plate count, far more than one cook can make. One server cannot take 16,700 requests a second. A bigger machine, or more machines?

Check yourself

Check yourself

Arjun says: “The day’s average is about 116 a second and one server takes 200, so we are fine.” What is wrong?

Pick an answer to see why it is right or wrong.

Check yourself

Nandini cannot tell whether her 800 guests will eat 3 or 4 rotis each. What does a good estimator do?

Pick an answer to see why it is right or wrong.

Check yourself

Each tap takes 0.2 seconds and 200 taps arrive every second. About how many taps are in progress at once?

Pick an answer to see why it is right or wrong.

Try it yourselfModule recap: thinking in numbers firstSix quick calls from this module. Tap the best answer.

Remember these three

  1. Rough numbers decide the design, and the peak, not the average, is the design.
  2. To find the peak, divide total requests by the seconds they arrive in. To find servers, divide the peak by what one takes, and round up.
  3. Say every guess out loud, round to powers of ten, add headroom, and check the biggest guess first.

Questions people ask

How to do capacity estimation in system design?
Write down your guesses for users and requests each, and multiply them. Divide by the seconds they arrive in to get the peak, then by what one server handles. Work out storage too, and design for the biggest number.
How to calculate QPS?
Divide the total requests by the seconds they arrive in. For SeatJaldi, 1 crore requests in 600 seconds is about 16,700 a second at the peak. Spread over a day, it is only about 116.
How many servers do I need?
Divide the peak by what one server can handle, round up, then add headroom. For SeatJaldi, 16,700 divided by 200 is about 84 servers, or about 167 with 2x headroom.
How accurate does a capacity estimate need to be?
Being within about ten times of the truth is usually enough, because the aim is to choose a design. Say your guesses out loud, and check the biggest one first.