Assuming:
Storage estimation:
Bandwidth estimation:
1. Shorten URL
Endpoint: POST /api/v1/shorten
Request: {
"url": "https://www.example.com/very/long/url",
"custom_alias": "myurl" (optional),
"expiry_date": "2024-12-31" (optional)
}
Response: {
"short_url": "http://tny.io/abcd123",
"expiry_date": "2024-12-31"
}
2. Redirect
Endpoint: GET /{short_code}
Response: HTTP 301 redirect to original URL
3. Get URL Analytics
Endpoint: GET /api/v1/analytics/{short_code}
Response: {
"short_url": "http://tny.io/abcd123",
"original_url": "https://www.example.com/very/long/url",
"creation_date": "2023-07-26",
"expiry_date": "2024-12-31",
"total_clicks": 1500
}
Table: urls
Table: users (optional)
Frontend: Interface for users to interact with the service.
Backend: API to handle URL shortening, redirection, and analytics.
Database: Storage for URL mappings and analytics data.
Cache: Use a caching layer (e.g., Redis) to store frequently accessed data for faster redirection.
Load Balancer: Distribute incoming traffic across multiple backend servers
URL Shortening:
URL Redirection:
Load Balancer: Use a software load balancer like HAProxy or NGINX
Web Servers: Lightweight web servers like NGINX to handle HTTP requests
Application Servers: Use a language with good concurrency support (e.g., Go, Node.js)
Cache: Redis for fast key-value storage of URL mappings
Database: Use a relational database like PostgreSQL for primary storage
URL Shortening Algorithm: Base62 encoding of an auto-incrementing ID or random string generation
Analytics Service: Separate microservice for processing and storing click data