Sub topic 6
From daily active users to queries per second
This chapter assumes you can do arithmetic with large numbers and exponents, and that you know what a client, a server and a load balancer do. You should also have the 86,400-second day from the previous chapter in mind. Reading simple Python helps but is optional.
Why queries per second
Product requirements usually arrive as daily active users (DAU), the number of distinct users who use the product on a given day. Servers and databases are sized by queries per second (QPS), the number of requests the system handles each second. The conversion between the two is the first step in most estimates.
The basic formula
Average QPS is the total number of requests in a day divided by the number of seconds in a day.
- Start with DAU.
- Multiply by the average number of requests each active user makes per day.
- Divide by 86,400 seconds, or by 100,000 if you want to round for mental math.
dau = 10_000_000
requests_per_user_per_day = 10
seconds_per_day = 86_400
peak_factor = 2
avg_qps = dau * requests_per_user_per_day / seconds_per_day
peak_qps = avg_qps * peak_factor
print(round(avg_qps)) # 1157
print(round(peak_qps)) # 2315Here 10 million users make 10 requests each, which is 100 million requests per day. Dividing by 86,400 gives about 1,157 QPS on average.
Rounding for mental math
You rarely have a calculator in a design discussion. Round 86,400 up to 100,000 and the same example becomes 100 million divided by 100,000, which is 1,000 QPS. The result is about 14% lower than the exact figure. That error is small next to the uncertainty in the inputs, and the order of magnitude is the same.
Choosing requests per user
The requests-per-user number is an assumption, so state it. Define what counts as a request first. One page view may trigger five API calls, and a feed that refreshes in the background makes more calls than a user who opens the app once. Separate reads from writes, because they load different parts of the system.
| Quantity | Assumption | Result |
|---|---|---|
| DAU | 10 million | |
| Reads per user per day | 10 | 100 million reads per day, about 1,157 QPS |
| Writes per user per day | 1 | 10 million writes per day, about 116 QPS |
| Read to write ratio | 10 to 1 |
Splitting the traffic this way pays off later. Storage depends on writes, while cache sizing depends on reads.
Average is not peak
Traffic is not spread evenly across the day. Users cluster in the evening, around events and after notifications. A system sized for average QPS will be overloaded during busy hours. The usual shortcut is a peak factor, a multiplier applied to the average. A factor of 2 is a common starting point, and spiky products may use 5 or more. Say which factor you chose and why. The next chapter treats peak load in more detail.
Common errors
- Forgetting that DAU is not total users. Monthly or registered users overstate daily load. Use DAU, or convert with an assumed ratio.
- Dividing by the wrong number of seconds. A day has 86,400 seconds. Dividing by 24 gives requests per hour, not per second.
- Mixing units. Keep millions and thousands consistent. 10 million times 10 is 100 million, not 1 billion.
- Treating the result as exact. Report 1,157 QPS as "about 1,000 QPS" or "about 1.2K QPS".
- Ignoring fan-out. One user request can trigger several backend calls. Decide whether you are counting edge requests or internal calls.
Exercise
Exercise
A chat app has 50 million DAU. Each user sends 40 messages per day. Using 100,000 seconds per day for mental math and a peak factor of 3, what are the approximate average and peak write QPS?
Show answer
Messages per day are 50 million * 40 = 2 billion. Dividing by 100,000 gives 20,000 average QPS. Multiplying by 3 gives about 60,000 peak QPS. With 86,400 seconds the exact average is about 23,148 QPS, so the rounded figure is within the same order of magnitude.