/shortenPOST{ "longUrl": "https://www.example.com/some/very/long/url", "customAlias": "optional-custom-alias", "userId": "optional-user-id-for-authenticated-users"}
{ "shortUrl": "https://short.url/abc123", "shortUrlExpire": "2023-12-31T23:59:59Z" // If expiration is set}
/redirect/{shortUrl}GETshortUrl: The unique alias of the shortened URL/stats/{shortUrl}GETshortUrl: The unique alias of the shortened URL{ "shortUrl": "https://short.url/abc123", "originalUrl": "https://www.example.com/some/very/long/url", "clicks": 150, "createdAt": "2023-01-01T00:00:00Z", "lastAccessed": "2023-11-01T10:00:00Z"}
/registerPOST{ "username": "user123", "password": "securePassword", "email": "[email protected]"}
{ "message": "User registered successfully", "userId": "newly-created-user-id"}
/loginPOST{ "username": "user123", "password": "securePassword"}
{ "token": "jwt-token-for-authentication"}
/user/urlsGETAuthorization: Bearer {token}[ { "shortUrl": "https://short.url/abc123", "originalUrl": "https://www.example.com/some/very/long/url", "createdAt": "2023-01-01T00:00:00Z" }, { "shortUrl": "https://short.url/def456", "originalUrl": "https://www.example2.com/another/long/url", "createdAt": "2023-01-02T00:00:00Z" }]
/shorten endpoint./redirect/{shortUrl} endpoint.Here's an ER diagram representing these entities and their relationships:
USERstringidPrimary KeystringusernameUser's usernamestringpassword_hashHashed passwordstringemailUser's emaildatecreated_atRegistration dateURLstringidPrimary Keystringlong_urlOriginal long URLstringshort_urlGenerated short URLstringuser_idForeign Key referencing USERdatecreated_atDate URL was shorteneddateexpires_atExpiration date (if applicable)URL_STATSstringidPrimary Keystringurl_idForeign Key referencing URLintclick_countNumber of clicksdatelast_accessedLast accessed timestampcreateshas
id: Unique identifier for each user.username: Username chosen by the user.password_hash: Securely stored hashed version of the password.email: User's email address.created_at: When the user registered.id: Unique identifier for each URL entry.long_url: The original long URL that needs shortening.short_url: The generated short URL alias.user_id: References the user who created the short URL.created_at: When the URL was shortened.expires_at: Optional expiration date for the shortened URL.id: Unique identifier for each statistics record.url_id: References the shortened URL's entry in the URL table.click_count: Tracks the total number of times the short URL was accessed.last_accessed: Records when the URL was last accessed.For a high-level design of a URL shortening service, we need to identify the key components required to handle all the functionalities we've discussed, ensuring that the system operates efficiently from end to end.
Here's a block diagram that illustrates these components and how they interact:
HTTP Requests
Shorten URL
Save Mapping
Redirect
Lookup URL
Return Long URL
Redirect User
Analytics Data
User Requests
Collect Data
Client
API Gateway
URL Shortening Service
Database
Redirect Service
Analytics Service
User Management Service
Monitoring and Logging
Explain how the request flows from end to end in your high level design. Also you could draw a sequence diagram using the diagramming tool to enhance your explanation...
Dig deeper into 2-3 components and explain in detail how they work. For example, how well does each component scale? Any relevant algorithm or data structure you like to use for a component? Also you could draw a diagram using the diagramming tool to enhance your design...
Explain any trade offs you have made and why you made certain tech choices...
Try to discuss as many failure scenarios/bottlenecks as possible.
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?