Requirements


Functional Requirements:


  • Create a short URL for a given long URL.
  • Return the long URL associated with a given short URL.



Non-Functional Requirements:


  • Redirect should happen in <50ms
  • Target 99.99% uptime
  • Assume 100M urls per month and 10B redirects per month
  • Read-heavy
  • A URL created should never be lost
  • Cache aggressively to reduce database load


API Design

  • A POST endpoint to take in long urls and return the shortened version
  • A GET redirect
  • A GET for metadata (optional)



High-Level Design

  1. API Gateway / Load Balancer
  2. URL Creation Service
  3. Redirect Service
  4. Cache
  5. URL Database
  6. ID Generator




Detailed Component Design

Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.