Visual Solution

Estimate QPS for a URL Shortener

A URL shortening service creates 500 million new short URLs per month. The read-to-write ratio is 100:1. Estimate the write QPS and read QPS.

Solution PathTarget: 5 min
Convert monthly traffic to per-second QPS, then apply the read:write ratio. The 100:1 ratio reveals this is an extremely read-heavy system that must be optimized for fast redirects.
01Problem Setup
1/4
We are given 500 million new short URLs created per month, with a read-to-write ratio of 100:1. We need to estimate write QPS and read QPS.
Given: 500M new URLs/month, read:write ratio = 100:1
02Calculate Write QPS
2/4
Convert monthly writes to per-second: divide 500 million by the number of seconds in a month (30 days * 24 hours * 3600 seconds = 2,592,000 seconds).
Write QPS = 500,000,000 / 2,592,000 = ~200 writes/sec
03Calculate Read QPSKEY INSIGHT
3/4
The read-to-write ratio of 100:1 means for every URL created, it gets redirected 100 times. Multiply write QPS by 100 to get read QPS. This tells us the system is extremely read-heavy.
Read QPS = 200 * 100 = 20,000 reads/sec
04Final Answer
4/4
At 20K reads/sec, the read path dominates. This means we must optimize for fast lookups: aggressive caching (Redis), read replicas, and potentially CDN edge caching for popular URLs.
~200 writes/sec, ~20,000 reads/sec. Optimize the read path first.
Concepts from this question2 concepts unlocked

Read-Heavy Caching (Cache-Aside)

STANDARD

A caching pattern where the application checks the cache first, falls back to the database on a miss, and populates the cache before returning. Ideal for read-heavy workloads.

Hit rate80%    DB load reduced by 5×\text{Hit rate} \geq 80\% \implies \text{DB load reduced by } 5\times

URL shorteners have a 100:1 read:write ratio. Caching the top 20% of URLs serves 80% of traffic (Zipf distribution), dramatically reducing database load.

url-q8url-q10
Practice (2 Qs) →

Base62 Encoding

EASY

An encoding scheme using 62 characters [a-zA-Z0-9] to convert numeric IDs into compact alphanumeric strings. Each character represents a digit in base-62.

62n unique codes for n characters    6273.5×101262^n \text{ unique codes for } n \text{ characters} \implies 62^7 \approx 3.5 \times 10^{12}

Base62 maps auto-incrementing IDs to short, URL-safe strings with zero collision probability. It is the preferred encoding for most URL shortener designs.

url-q3url-q5url-q10
Practice (3 Qs) →