1. Design a URL Shortener

Medium

Design a URL shortening service similar to bit.ly that can handle millions of URLs and provide analytics.

Example

Input: https://www.example.com/very/long/url/path

Output: https://short.ly/abc123

Functional Requirements
  • Shorten long URLs into short, unique identifiers
  • Redirect users to original URLs when they visit the short URL
  • Allow custom aliases (optional)
  • Set expiration time for URLs
  • Provide basic analytics (click count, geographic data)
Nonfunctional Requirements
  • High availability (99.9%)
  • Low latency for redirects (<100ms)
  • Scalable to handle millions of URLs
  • Read-heavy system (100:1 read to write ratio)
Assumptions
  • URL shortening service is read-heavy
  • Users can create custom aliases
  • Analytics data is important
  • URLs don't expire by default
Estimated Usage
  • 100 million URLs shortened per month
  • 10 billion redirections per month
  • Read to write ratio: 100:1
  • Peak QPS: 4000

Seen this question in a real interview before?

Companies

Not all editor features are supported on mobile