List functional requirements for the system (Ask the chat bot for hints if stuck.)...
1) Shorten URL : Take long URL and return shortened URL
2)Redirect: When short URL is called redirect to Long URL
3)Analytics: Provide analytics of number user clicks/redirects etc.
4)Expiry: User can define expiry of URL
5)API design: provide API for dev to integrate the URL shortening
1)Performance: System should handle thousand request per second, with less than 100ms delay
2)Scalability: The architecture should support horizontal scaling to accommodate increasing traffic
3)Reliability: The system should have 99.99% uptime.
4)Security: Implementing measures to prevent abuse such as rate limiting.
5)Data Integrity: Ensure that all shortened URLS point to correct long URLs.
6)User privacy: Avoid storing unnecessary user data
traffic : 1million user request per day
data volume of 1 request= 1kb
storage required for a day = 10^6 * 1kb= 1GB
Storage required over the year = 365GB
We can consider a 1TB monolithic server for the initial design
REST API
1) POST /shorten-url/
Request Body
{
"longUrl":"asfafaffafafafafafasdf".
"expiryDateTime":"2024-10-31 10:15:00"
}
2)GET /get-url/{shorten-url}
Rate limit post url to prevent DDOS attack
Defining the system data model early on will clarify how data will flow among different components of the system. Also you could draw an ER diagram using the diagramming tool to enhance your design...
url_shortner_table
id
long_url
short_url
expiry_date_time
createdAt
createdBy
create a read replica for read request to be handled via sharding
URL Shortening Algorithm:
Use base62 encoding to create short codes with alphanumeric characters.
Cache:
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?
Mitigation: Implement a failover mechanism with read replica databases or a high-availability setup. Utilize connection pooling and graceful degradation to ensure continued read operations.