Functional Requirements:
Non-Functional Requirements:
Daily Requests: Estimate of 10 million requests per day.
Storage: Assume 1 KB per URL mapping, storing 100 million URLs would require around 100 GB of storage.
Traffic: Peak traffic handling of 1000 requests per second.
1. Create Short URL:
POST /api/shorten
{
"longUrl": "http://example.com/very/long/url",
"customAlias": "optional-custom-alias"
}
Response:
{
"shortUrl": "http://short.url/abcd1234"
}
2. Retrieve Original URL:
GET /api/original/:shortUrl
Response:
{
"longUrl": "http://example.com/very/long/url"
}
3. Get URL Analytics:
GET /api/analytics/:shortUrl
Response:
{
"clicks": 1023,
"geography": {
"US": 600,
"IN": 200,
"Other": 223
}
}
Entities:
id (PK)longUrl (String)shortUrl (String, Unique)customAlias (String, Unique, Optional)createdAt (DateTime)clicks (Integer)id (PK)shortUrl (FK)timestamp (DateTime)geoLocation (String)Components:
Shortening URL:
Redirection:
sequenceDiagram
Client->>API Gateway: POST /shorten
API Gateway->>URL Shortening Service: Create short URL
URL Shortening Service->>Database: Store URL mapping
Database->>URL Shortening Service: URL stored
URL Shortening Service->>API Gateway: Short URL
API Gateway->>Client: Return short URL
User->>Redirection Service: Access short URL
Redirection Service->>Database: Get long URL
Database->>Redirection Service: Return long URL
Redirection Service->>User: Redirect to long URL
Redirection Service->>Analytics Service: Log click data
1. URL Shortening Service:
2. Redirection Service:
3. Analytics Service:
Hashing vs. Sequential IDs: Hashing provides better distribution but might have collisions; sequential IDs are simple but predictable.
SQL vs. NoSQL: SQL provides strong consistency; NoSQL provides better scalability.
Database Failures: Use replication and backups to prevent data loss.
Service Downtime: Implement auto-scaling and load balancing to handle traffic spikes.
Data Corruption: Regular data integrity checks and audits.
Custom Domains: Allow users to use their own domains for short URLs.
Enhanced Security: Implement features like rate limiting and URL validation.
Advanced Analytics: Provide more detailed analytics, such as user agent and referrer tracking.