Whole systems / 2 / 4
Design a URL shortener
A long link goes in, a short code comes out, and every click is a redirect. We build the whole service step by step: estimates, short codes, the redirect, cache, replicas, click analytics, aliases and expiry.
- 13 min
- Intermediate
- 12 steps
- Redirect p99
- 30 ms
- Reads on primary
- 300 /s
- Code collisions
- 0 /day
- request
- reply
- redelivery
- duplicate
- lost
Numbers are a model scenario, not measurements
The real request
Browser → Link APIRequest
POST /api/links HTTP/1.1
Host: api.example.com
Content-Type: application/json
{
"long_url": 1"https://shop.example.com/sale/42"
}
Response
HTTP/1.1 201 Created
{
"code": 2"8sujL",
"short_url": 3"https://sho.example/8sujL"
}
long_url— The destination. Validate it: scheme, length, and a blocklist of known phishing hosts.code— The short key. It is the primary key in the links table and the cache key later.short_url— What the user shares: our short domain plus the code.
Course: 42 lessons
01 Foundations
02 Scaling
03 Data & storage
04 Communication
05 Reliability
06 Architecture
07 Security
08 Shipping
09 Whole systems
10 Business processes