Requests per second and peak traffic
From people to a rate
Section titled “From people to a rate”Every capacity question starts with a number of people and ends with a number of machines. In between there are three steps, and the first lesson of the module takes them one at a time.
- Requests per day. The daily active users times the requests each one makes: D = U × q.
- Average requests per second. The day’s total divided by the seconds in a day: A = D ÷ 86,400.
- Peak requests per second. The average times how many times busier the busiest moment is: P = A × f.
Mental model. A day’s traffic is a volume, and machines are bought for a rate. Divide the volume by the seconds in a day to get the average rate, then multiply by how much busier the busiest moment is. The peak is the number to size for.
Google’s SRE book describes capacity planning as starting from a demand forecast: how many resources are needed, and when and where. For a web system the first forecast is this one. Jon Bentley’s column on back-of-the-envelope calculation makes a point that suits it: the arithmetic is usually simple, and the hard part is remembering to do it early in a project.
Try it: the shop’s traffic
Section titled “Try it: the shop’s traffic”The shop from the first module has a million active users a day, each making about 40 requests, and its busiest moment is about four times the average. The calculator below starts on those numbers. Its fields are Daily active users (in millions), Requests per user per day and Peak-to-average ratio.
Traffic calculator
Your numbers
How many different people use the product on a typical day: daily active users, not registered accounts.
Count the requests that reach the system, not the screens the user sees: opening one page can send ten requests.
How many times busier the busiest moment is than the average. It depends on the product and on time zones, so take it from your own traffic when you can. The starting 3 is only a round number for illustration.
Changing the numbers needs JavaScript. The result is for the starting numbers.
Result
Peak requests per second1.85K
On average: 463 requests per second.
How it is calculated
Each step shows its formula, the numbers that go in, and the figure that comes out.
Requests per day
D = U × q
Every user makes the same number of requests, so the day's total is the number of users times the requests each one makes.
- U daily active users
- 1M
- q requests per user per day
- 40
D requests per day40M
Average requests per second
A = D ÷ d
Spread over the whole day. A day has 86 400 seconds; in back-of-envelope mode it is taken as 100 000.
- D requests per day
- 40M
- d seconds in a day
- 86.4K
A average requests per second463
Peak requests per second
P = A × f
A system is sized for its peak, not for its average.
- A average requests per second
- 463
- f peak-to-average ratio
- 4
P peak requests per second1.85K
| Requests per day | Average per second |
|---|---|
| 1M | 11.6 |
| 10M | 116 |
| 40M · your traffic | 463 |
| 100M | 1.16K |
| 1B | 11.6K |
| 10B | 116K |
Model notes
Assumptions
- Every user makes the same number of requests. Real users do not: a few heavy users, bots and automatic retries add requests, so measure the spread if it matters.
- The peak is the average times the ratio you enter. Real peaks depend on the product, the time of day and the time zones of the users, and a single event can exceed any ratio, so take it from your own traffic.
Simplifications
- A day has 86 400 seconds. In back-of-envelope mode it is taken as 10^5 seconds, the nearest power of ten, so the averages come out about 14% lower than the exact ones.
- In back-of-envelope mode, the counts and sizes you enter are rounded to the nearest power of ten before anything is calculated. The result is an order of magnitude, not a figure to buy against.
Parameter values are illustrative. They are not benchmarks of any real product.
Follow the steps. A million users making 40 requests each is 40,000,000 requests a day. Divided by 86,400 seconds, that is 463 requests per second on average. Four times that is about 1,850 at the peak, which the first module rounded up to a requirement of 2,000 (Requirements).
The table under the steps gives a figure worth remembering: a million requests a day is about 12 a second. Ten million is about 116, and a billion is about 11,600.
The 40 requests are requests that reach the system, not screens. A user who opens four screens a day, each sending ten requests, makes 4 × 10 = 40. Bots, retries and health checks add requests that no user chose to make, so the count is only as good as what you know of them.
The ratio is the weakest number
Section titled “The ratio is the weakest number”The peak-to-average ratio is the least certain of the three inputs. It depends on the product, on the time of day and on the time zones of the users. Users concentrated in one time zone tend to make the busiest moment much busier than the average, and users spread over many tend to flatten it. That is reasoning, not a measurement, and a sale or a broadcast can exceed any ratio you chose.
Take the ratio from your own traffic when you have it. The calculator starts at 3 and this lesson uses 4: both are round numbers for illustration. Without data, run the estimate with a low and a high ratio, and see whether the answer would change the design.
Two different numbers do two different jobs, and the exercise below tests whether you can tell which a question needs.
Challenge
Peak or average?
An estimate uses two different numbers for traffic. Capacity has to carry the peak, the busiest moment. A total over a day or a month is built from the average, because the average rate times the time is what was actually served. Put each question under the number it needs.
Sorting needs JavaScript.
Categories
- The peak
- The busiest moment: what has to be carried.
- The average
- Spread over the whole period: what adds up to a total.
Check your answers at least once before looking at the answers.
From a rate to instances
Section titled “From a rate to instances”A rate is useful because machines have rates too. Suppose one instance can serve at most 400 requests per second. That figure is illustrative: you would measure it with a load test of your own service.
The performance module showed that time in a service climbs steeply as utilisation approaches 100% (Utilisation and queueing), so you do not plan to run at the limit. Take a target of 60% at the peak. That is a choice, not a rule. One instance then carries 0.6 × 400 = 240 requests per second, and the shop needs 1,852 ÷ 240 = 7.7, which rounds up to 8 instances.
Eight instances can serve at most 8 × 400 = 3,200 requests per second, so at the peak they run at 1,852 ÷ 3,200 = 58%. The rounding up is where the margin comes from.
What happens if the peak is 10 times the average?
Section titled “What happens if the peak is 10 times the average?”Set the ratio to 10 instead of 4. The average does not change, and the peak becomes 4,630 requests per second.
The 8 instances can serve 3,200. The demand is 4,630 ÷ 3,200 = 145% of their capacity. Above 100% there is no steady state: the queue grows for as long as the peak lasts, and requests wait, time out or fail. To carry 4,630 at the same 60% target the shop needs 4,630 ÷ 240 = 19.3, which is 20 instances, 2.5 times as many as before.
The factor of 2.5 is the ratio of the ratios, 10 ÷ 4. Every figure that follows from the peak moves by it: instances here, and the link speed in the lesson on bandwidth. A later module covers adding instances as load rises. Whatever it does, the first minutes of a surge are served by the fleet that already exists. This is why the ratio, the weakest number, deserves the most care.
- Traffic is estimated in three steps: requests per day are users times requests each, the average per second is that divided by 86,400, and the peak is the average times the peak-to-average ratio.
- For the shop, 1 million users making 40 requests are 40,000,000 requests a day, 463 per second on average and about 1,850 at the peak with a ratio of 4. A million requests a day is about 12 per second.
- Capacity is sized for the peak. Totals over time, such as a month’s requests or a day’s data, are built from the average.
- At 400 requests per second per instance and a 60% target, the peak of 1,852 needs 8 instances, which then run at 58%.
- The ratio is the weakest input. At 10 instead of 4 the peak is 4,630, which is 145% of the capacity of 8 instances, and the same target needs 20.
Next: storage and retention, and why data stops growing when old data is deleted.
Your progress
Built by GhaziAlibi.
© ShardCraft. All rights reserved.