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.
- The service checks the DB to see if the long URL already exists
- If the long URL does exist then we return the existing shortened URL
- FI the long URL does not exist we create a new shortened URL
- Create a PK for the id of the long and short URL
- Generate the short URL using x method
- Store the short and long and PK in the table
- 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.