Skip to content
BytePatterns

URL Shortener Capacity Estimate

EasySystem Design Cases#capacity-estimation#back-of-the-envelope~15m

Problem

Turn the opening numbers of a URL shortener interview into a capacity estimate. Given new short links per day, reads per write, bytes stored per link, years of retention and a peak-to-average factor, return a dict with: write_qps and read_qps, the average requests per second, rounded up; peak_read_qps, reads per day times the peak factor per second, rounded up; storage_tb, all links kept for the retention period in terabytes of 10¹² bytes, rounded to 1 decimal; and code_length, the shortest code over 62 characters (a-z, A-Z, 0-9) with room for every link. Use 86,400 seconds per day and 365 days per year, with integer arithmetic for the rounding up.

Examples

Input:  new_per_day = 100_000_000, reads_per_write = 100, bytes_per_url = 500, years = 10, peak = 3
Output: {'write_qps': 1158, 'read_qps': 115741, 'peak_read_qps': 347223, 'storage_tb': 182.5, 'code_length': 7}
Why:    365 billion links need 7 characters, because 62⁶ is only about 57 billion
Input:  new_per_day = 1_000_000, reads_per_write = 10, bytes_per_url = 500, years = 5, peak = 2
Output: {'write_qps': 12, 'read_qps': 116, 'peak_read_qps': 232, 'storage_tb': 0.9, 'code_length': 6}
Why:    a service 100 times smaller still needs 6 characters, since 62⁵ is under a billion
Input:  new_per_day = 1, reads_per_write = 1, bytes_per_url = 100, years = 1, peak = 1
Output: {'write_qps': 1, 'read_qps': 1, 'peak_read_qps': 1, 'storage_tb': 0.0, 'code_length': 2}
Why:    edge case, rounding up keeps every rate at least 1, and 365 links already overflow 62 one-character codes

Hints

0 / 3

Stuck on the idea rather than the code? Design a URL Shortener covers it.