URL Shortener: Estimates
How big.
Now some quick math. How many requests per second, and how much storage? This tells us where the hard parts are.

- Quick math
- Requests per second
- Storage
Estimating the shortener
A hundred million new links a month. People read links far more than they create them, so let's assume a hundred reads per write. Each record is about five hundred bytes. Run it. About forty writes per second, but almost four thousand reads per second. And three terabytes of data over five years.
links_month = 100_000_000
reads_per_write = 100
record_bytes = 500
seconds_month = 30 * 86_400
writes = links_month / seconds_month
print(f"writes/sec: {writes:,.0f}")
print(f"reads/sec: {writes * reads_per_write:,.0f}")
total = links_month * 12 * 5
print(f"links in 5 years: {total / 1e9:.0f} billion")
print(f"storage: {total * record_bytes / 1e12:.0f} TB")writes/sec: 39 reads/sec: 3,858 links in 5 years: 6 billion storage: 3 TB
What the numbers tell us
The numbers shape the design. It's very read heavy, so caching redirects is the big win. Six billion links need short codes with enough room. And three terabytes fits in a sharded database comfortably. Writes, at forty per second, are easy.
| key | value |
|---|---|
| Read heavy | cache the redirects |
| 6 billion links | codes need room |
| 3 TB | shard, but modest |
| Writes | easy |
Summary
The shortener is read heavy, with about four thousand reads a second, and six billion links over five years. Next, making the short codes.
Key takeaways- ~40 writes/sec
- ~4,000 reads/sec
- 6 billion links, 3 TB