-> daily storage requirement 1Million * 5KB ~= 5GB
-> TPS 1million /(24 *3600) ~= 12 TPS
1.Create short URL from given one.
/shorten. POST body {"inputURL": "xxx"} response {"shortURL": "abc", Id: '123"}
2.Redirect by Id(optional)
/redirect/Id
3.Delete Short URL
/delete/id
4.Analytics
/analytics/id
topReferrer: xxx click: xxx
5.Security
Rate limit: based on ip/session id limit max queries per day avoid DDOS.
Validation: check user input URL with regex match before handle it.
Use HTTPS redirection: protect service from being intercepted.
6.User Registration
Allow users to sign up for an account by providing essential information such as email address and password. Optionally, you can offer signup via third-party services (e.g., Google, Facebook) for convenience.
/registerPOSTjson
Copy code
{ "email": "[email protected]", "password": "securePassword123" }
email verification
reset password
User Table
1.user id(key)
2.email
4.pwd
5.email verified boolean
URLs table
1.short URL(key)
1.id
2.user id
3.original URL
4.createdAt
5.ExpiresAt
6.shortCode
1.visit id(key)
1.short URL id
2.ReferrerIdAndClicks {"referrer1": 10, "referrer2": 2}
3.
4.
User interactions:
URL Shorten:
URL redirection
analytics
Each access to a shortened URL is logged by the Analytics Service, which updates visit counts, referrers, and other relevant data in the database for reporting to the user.
Let's delve into the process of generating unique shortened URLs and handling collisions in the system
Generation strategy:
pro and cons
Explain any trade offs you have made and why you made certain tech choices...
Scenario: High request rates could overload the database, slowing down read and write operations, leading to timeouts or errors.
Mitigation:
Scenario: If any component of the system (e.g., the API Gateway, database, or key generation service) is a single point of failure, its outage could make the entire service unavailable.
Mitigation:
Scenario: The method for generating unique identifiers for shortened URLs might lead to collisions, especially as the namespace gets crowded, impacting performance due to retries.
Mitigation:
Caching: Maintain a cache of recently accessed or created short URLs to reduce database lookups for popular or newly generated URLs. LRU cache