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
Capacity Estimation
Estimate the scale of the system. Consider daily active users, read/write ratio, storage requirements, bandwidth, and any relevant QPS calculations...
API Design
We need two API endpoints.
POST /create
Takes a URL in the POST body and returns the unique ID associated with the URL.
GET /{id}
Returns the URL associated with the ID.
High-Level Design
When creating a short-URL, the server adds a row to a database column contains the ID and the URL. For low latency, we use a redis cache for retrieval requests to avoid excessive database requests.
Database Design
Let us keep it simple and have a table with 3 columns: id, shorturl_id, url.
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.