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:


  • low latency
  • unique URLs for every shortened URL
  • data retention


API Design

POST - /shorten - accept long URL and return the shortened URL

  • 400 internal error
  • 200 success



GET - /redirect accept the shortened URL and redirect to the long URL

  • 404 not found
  • 200 success
  • 400 internal error


High-Level Design


shorten endpoint takes in a longURL.


  1. The service checks the DB to see if the long URL already exists
  2. If the long URL does exist then we return the existing shortened URL
  3. FI the long URL does not exist we create a new shortened URL
  4. Create a PK for the id of the long and short URL
  5. Generate the short URL using x method
  6. Store the short and long and PK in the table
  7. Return the shortened URL


It checks



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.