Design a URL Shortener (TinyURL): Interactive System Design
URL Shortener
Guided ModeStep 1 β The Basic System
Request Flow
1
Store a URL (POST /shorten)
Browser sends POST /shorten with the long URL to the API Server.
POST /shorten
{ url: "https://verylongurl.com/article" }
β INSERT INTO urls (code, long_url, created_at)
VALUES ('abc123', 'https://...', NOW())
β 201 { short_url: "https://short.ly/abc123" }2
Redirect a visitor (GET /:code)
Browser visits /abc123. The API Server queries the Database for the long URL, then returns a 302 redirect.
GET /abc123 β SELECT long_url FROM urls WHERE code = 'abc123' β 302 Found Location: https://verylongurl.com/article
Why We Need This
Every URL shortener at its core is just two operations: write the mapping, read it back for redirect.
This simple three-component system handles thousands of requests per second β until the Database becomes the bottleneck on read-heavy traffic.
Key Insight
Two endpoints define the whole product: POST /shorten (write once) and GET /:code (read many times). Optimize the read path β that's where 99% of traffic goes.
Step 1 of 6
