DSA, High & Low Level System Designs
1. API for URL Shortening
Endpoint:
POST /shorten
Description:
Converts a long URL into a short URL.
Request:
{
"long_url": "https://www.example.com/some-very-long-url",
"custom_alias": "myshorturl", // Optional
"expiry_date": "2025-12-31T23:59:59Z" // Optional
}
Response:
{
"short_url": "https://tinyurl.com/abc123"
}
Notes:
Generates a unique short URL.
Supports custom aliases if available.
Allows optional expiration date.
2. API for URL Redirection
Endpoint:
GET /{short_url}
Description:
Redirects the user from a short URL to the original long URL.
Example Request:
GET /abc123
Response:
- 302 Redirect to:
https://www.example.com/some-very-long-url - 404 Not Found if the short URL does not exist.
Notes:
Fast lookup from the database or cache.
Supports logging and analytics.
Handles expired or deleted URLs.
3. API for Fetching Original URL
Endpoint:
GET /expand/{short_url}
Description:
Returns the original long URL for a given short URL.
Example Request:
GET /expand/abc123
Response:
{
"long_url": "https://www.example.com/some-very-long-url",
"created_at": "2024-01-01T12:00:00Z",
"expiry_date": "2025-12-31T23:59:59Z"
}
Notes:
Useful for previewing or validating URLs.
Can be restricted for security.
4. API for URL Analytics
Endpoint:
GET /analytics/{short_url}
Description:
Returns analytics data for a short URL.
Example Request:
GET /analytics/abc123
Response:
{
"short_url": "https://tinyurl.com/abc123",
"long_url": "https://www.example.com/some-very-long-url",
"clicks": 12000,
"unique_visitors": 8000,
"geo_distribution": {
"US": 5000,
"India": 3000,
"UK": 2000
},
"referrers": {
"Google": 4000,
"Facebook": 3000,
"Twitter": 2000
},
"created_at": "2024-01-01T12:00:00Z",
"expiry_date": "2025-12-31T23:59:59Z"
}
Notes:
Tracks total clicks, unique visitors, geolocation, and referrers.
Helps users analyze URL performance.
5. API for Deleting a Short URL
Endpoint:
DELETE /delete/{short_url}
Description:
Deletes a short URL from the system.
Example Request:
DELETE /delete/abc123
Response:
{
"message": "Short URL deleted successfully"
}
Notes:
Requires authentication to prevent abuse.
Supports soft delete (disabling instead of deleting).
6. API for Managing User's Short URLs
Endpoint:
GET /user/urls
Description:
Retrieves all short URLs created by a user.
Example Request:
GET /user/urls?user_id=12345
Response:
[
{
"short_url": "https://tinyurl.com/abc123",
"long_url": "https://www.example.com/some-very-long-url",
"clicks": 12000,
"expiry_date": "2025-12-31T23:59:59Z"
},
{
"short_url": "https://tinyurl.com/xyz789",
"long_url": "https://www.example.com/another-url",
"clicks": 5000,
"expiry_date": "2026-01-01T00:00:00Z"
}
]
Notes:
Allows users to manage their shortened URLs.
Supports pagination for large datasets.
7. API for Checking URL Availability
Endpoint:
GET /check/{custom_alias}
Description:
Checks if a custom short URL alias is available.
Example Request:
GET /check/myshorturl
Response:
{
"available": true
}
Notes:
Helps users choose a custom alias before shortening.
8. API for Bulk Shortening
Endpoint:
POST /shorten/bulk
Description:
Allows users to shorten multiple URLs at once.
Request:
{
"urls": [
"https://www.example.com/page1",
"https://www.example.com/page2",
"https://www.example.com/page3"
]
}
Response:
[
{
"long_url": "https://www.example.com/page1",
"short_url": "https://tinyurl.com/a1b2c3"
},
{
"long_url": "https://www.example.com/page2",
"short_url": "https://tinyurl.com/d4e5f6"
}
]
Notes:
Useful for businesses & marketing teams.
Security Considerations
Rate Limiting – Prevent API abuse.
Authentication (OAuth, API Keys) – Restrict sensitive endpoints.
Malware Detection – Block malicious URLs.