Sub topic 13
Worked example: estimating a URL shortener
This chapter chains the techniques from earlier chapters into one estimate. It assumes you can convert DAU to QPS, apply a peak factor, and multiply record size by retention. The system is a URL shortener. A user submits a long URL and gets a short code. Anyone who visits the short link is redirected to the long URL.
Step 1: State the assumptions
Write the assumptions down before calculating, so a reviewer can challenge each one.
| Assumption | Value |
|---|---|
| New short URLs per day | 100 million |
| Read-to-write ratio | 10 to 1 |
| Record size (code, long URL, metadata) | 500 bytes |
| Retention | 5 years |
| Peak factor | 2 |
| Redirect response size | 500 bytes |
| Cached share of daily reads | 20% |
| Capacity of one server | 5,000 QPS |
| Target utilization | 50% |
| Availability target | 99.99% |
Step 2: Follow the chain
Each result feeds the next one.
Step 3: Calculate
The script below performs every step. Run it to check the arithmetic.
import math
writes_per_day = 100_000_000
read_ratio = 10
reads_per_day = writes_per_day * read_ratio
seconds_per_day = 86_400
peak_factor = 2
record_bytes = 500
retention_days = 365 * 5
response_bytes = 500
cache_share = 0.2
server_qps = 5_000
utilization = 0.5
avg_write_qps = writes_per_day / seconds_per_day
avg_read_qps = reads_per_day / seconds_per_day
peak_write_qps = avg_write_qps * peak_factor
peak_read_qps = avg_read_qps * peak_factor
peak_total_qps = peak_write_qps + peak_read_qps
storage_tb = writes_per_day * record_bytes * retention_days / 1e12
egress_mbps = peak_read_qps * response_bytes * 8 / 1e6
ingress_mbps = peak_write_qps * record_bytes * 8 / 1e6
cache_gb = reads_per_day * cache_share * record_bytes / 1e9
servers = math.ceil(peak_total_qps / (server_qps * utilization))
print(round(avg_write_qps), round(avg_read_qps)) # 1157 11574
print(round(peak_write_qps), round(peak_read_qps)) # 2315 23148
print(storage_tb) # 91.25
print(round(egress_mbps, 1)) # 92.6
print(round(ingress_mbps, 1)) # 9.3
print(round(cache_gb)) # 100
print(servers) # 11Step 4: Round and read the results
| Quantity | Result | Rounded |
|---|---|---|
| Average writes | 1,157 QPS | about 1.2 thousand |
| Average reads | 11,574 QPS | about 12 thousand |
| Peak reads | 23,148 QPS | about 23 thousand |
| Storage | 91.25 TB | about 90 TB |
| Egress at peak | 92.6 Mbps | about 100 Mbps |
| Ingress at peak | 9.3 Mbps | about 10 Mbps |
| Cache | 100 GB | about 100 GB |
| Servers | 11 | about 10 to 12 |
These numbers support several design decisions:
- Reads outnumber writes ten to one, so caching and read replicas matter more than write throughput.
- 90 TB is too much for one ordinary database node but easy to shard across a few machines.
- 100 Mbps of egress is small, so bandwidth is not a bottleneck.
- 100 GB of cache fits in the memory of a few cache nodes.
Step 5: Check availability
At 99.99%, the allowed downtime is (1 − 0.9999) × 525,600 minutes per year, which is 52.56 minutes. A redirect service sits on the critical path of every link click, so this target is reasonable. It also rules out a single server or a single data center without failover.
Common mistakes in this example
- Forgetting that the 10 to 1 ratio makes reads 1 billion per day, not 100 million.
- Mixing bytes and bits when converting bandwidth. Multiply by 8 to get Mbps.
- Sizing the fleet for average QPS instead of peak QPS.
- Treating 91.25 TB as the final figure. Replication multiplies it. Three copies would need about 274 TB.
Exercise
Suppose the read-to-write ratio is 100 to 1 instead of 10 to 1, with the other assumptions unchanged. What is the new average read QPS, and how many servers do you need at peak?
Show answer
Reads per day are 100 million × 100 = 10 billion. Average read QPS is 10,000,000,000 / 86,400 ≈ 115,741. Peak read QPS is about 231,481, and peak write QPS stays at about 2,315. Peak total is about 233,796 QPS. Each server handles 5,000 × 0.5 = 2,500 QPS, so you need 233,796 / 2,500 ≈ 93.5, which rounds up to 94 servers.