Design a URL shortening service similar to TinyURL.
Requirements
Functional
-
Create a short URL for a given long URL.
-
Redirect: given a short code, redirect to the original long URL.
-
Custom aliases (optional): user can request a specific short code.
-
Expiration (optional): links may expire after a TTL.
-
Basic analytics (optional): clicks per link, referrer, country/device.
Non-functional
-
Low latency redirects (p99 in tens of milliseconds).
-
High availability.
-
Prevent abuse (spam/malware, high-rate creation).
-
Handle large scale (assume billions of URLs, high read:write ratio).
Deliverables
-
APIs, data model, and end-to-end flow.
-
Short code generation strategy.
-
Storage and caching design.
-
Scaling, partitioning, and reliability choices.
-
Handling collisions, deletions/expirations, and abuse.