Sub topic 2
Back-of-the-Envelope Estimation: Latency and Workload
Assume you know basic client-server architecture, databases, caches, and load balancers. The figures below are rough planning values, not performance guarantees.
Latency orders of magnitude
Latency is the time an operation takes. Order of magnitude means the approximate scale of a number. These reference figures help you compare designs:
| Operation | Rough latency |
|---|---|
| Memory access | 100 nanoseconds |
| SSD read | 100 microseconds |
| Network round trip in one region | 1 millisecond |
| Hard-disk seek | 10 milliseconds |
A memory lookup is about 10 times faster than an SSD read. An SSD read is about 10 times faster than a network round trip. A disk seek is often 10 times slower than a network round trip. Real values depend on hardware, distance, queueing, and request size.
From users to queries per second
Queries per second (QPS) is the average number of requests handled each second. Start with daily active users (DAU), multiply by requests per user, and divide by the seconds in a day:
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)) # 2315Peak load versus average load
Average QPS spreads activity evenly across 24 hours. Real traffic arrives in bursts. Multiply average QPS by a peak factor, such as 2, 5, or 10, based on product usage and historical data. Size critical components for peak load, while checking that the estimate does not include impossible simultaneous behavior.
Storage over a retention period
Multiply records per day by bytes per record and retention days:
new_records_per_day = 100_000_000
bytes_per_record = 500
retention_days = 365 * 5
total_bytes = new_records_per_day * bytes_per_record * retention_days
print(total_bytes / 1e12) # 91.25 TBThis excludes indexes, replication, metadata, and free space. Add those separately as headroom.
Exercise
A service averages 2,000 QPS and has a peak factor of 5. What peak rate should you plan for?
Show answer
Plan for about 10,000 QPS.