Design a URL shortener
System design, Medium
Design a service that turns a long URL into a short link and redirects visitors. Assume 100 million new links per month and 10 times more redirects than creations. Links live for 5 years. A redirect must answer in under 50 ms at the 99th percentile. Cover the API, how the short code is made, the storage choice, how you serve the read load, and one abuse risk. Out of scope: user accounts and the analytics dashboard (but say where click events go).
Examples
Input POST /links with { "url": "https://example.org/products/2026/summer-sale?ref=mail&id=88231" }
Output { "code": "aZ3k9Qx", "shortUrl": "https://sho.rt/aZ3k9Qx" }
Why The code has a fixed short length whatever the length of the long URL.
Input GET /aZ3k9Qx
Output A redirect response with a Location header holding the long URL, in under 50 ms at the 99th percentile.
Why This is the read path. The status code you pick is part of the design.
Input GET /zzzzzzz where no link has this code
Output HTTP 404, and the answer must not scan the whole store to find out.
Why Edge case: a code that does not exist is a normal request and must be cheap.
Constraints
- 100 million new links per month. Redirects are 10 times the creations.
- Links live for 5 years.
- A redirect answers in under 50 ms at the 99th percentile.
- Out of scope: user accounts and the analytics dashboard. Say where click events go.
Your answer must contain
- Requests per second and storage over the link lifetime, worked out from the numbers; the code format and length; the data model; the read path.