Design URL Shortener

Medium

Design a URL shortening service like Bitly or TinyURL. Handle billions of short links, high read throughput, custom aliases, analytics tracking, and link expiration at scale.

What to design

  1. What are the core functional requirements for the URL shortener?
  2. What are the non-functional requirements? Consider scale, latency targets, availability, consistency model, and storage growth over time.
  3. Design the core APIs — URL creation (with optional custom alias and TTL), redirection, analytics retrieval, and link management.
  4. How will you generate short, unique URL keys? Compare different approaches and their trade-offs.
  5. Which database would you choose for storing URL mappings? What's the schema and how would you partition the data?
  6. How would you design the caching layer to handle the read-heavy traffic pattern?
  7. Should the redirect use HTTP 301 or 302? How does this choice affect analytics and caching?
  8. How would you design the analytics pipeline to track clicks without adding latency to redirects?
  9. How do you handle link expiration and cleanup of expired URLs?
  10. How would you prevent abuse — spam, phishing links, and DDoS on the redirect endpoint?
  11. How would you scale this globally for low-latency redirects across regions?