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:
- List the key non-functional requirements (eg low latency, scalability, reliability, etc.)...
API Design
Endpoint for URL Shortening:
Method: POST
Endpoint: /shorten
Description: This endpoint takes a long URL and returns a shortened version.
Request Body:
{ "longUrl": "https://www.example.com/some/very/long/url"}
Response: { "shortUrl": "https://tinyurl.com/abc123"}
Error Handling: If the long URL is invalid, return a 400 Bad Request with a message like:
{ "error": "Invalid URL format."}
Endpoint for URL Redirection:
Method: GET
Endpoint: /{shortCode}
Description: This endpoint redirects the user to the original long URL based on the provided short code.
Example Request: GET /abc123
Response: This should perform a redirect (HTTP 302) to the long URL
Error Handling: If the short code does not exist, return a 404 Not Found with a message like:
{ "error": "Short URL not found."}
High-Level Design
Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.
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.