Generate shortened URLs,
Ability to get redirected by shortened URL,
Shortened URL management,
Ability to set expiration dates for URLs,
Dashboard for the users to preview traffic of shortened urls
Low-latency - the system should function without delays,
High availability - the function should prioritize availability over consistency in the case of network partitions,
Scalability - the system should be able to handle an increasing amount of traffic,
Security - sam links should not be accepted for shortening and users should be able to edit only their shortened links
100,000 DAU divided by 86,400 (seconds in a day), we can approximate to 100,000 seconds and when we divide both numbers we get 1 request per second. We can choose a ratio of 100:1 for the reads, meaning that the system will receive 100 read requests per second and 10 000 000 read requests per day.
POST /url - create a new shortened URL
GET /url/$link_url - redirect via shortened URL
One relational dabase with the following tables:
Users has the following schema:
user_id,
firstname,
lastname,
email,
password
UserLinks
user_id
link_id
Links
link_id
link_url
created_at
updated_at
total_visits
We could cache the most frequent request with a write-back strategy to optimize load on the backend and also use a TTL in order to invalidate cache
1:M relationship between Users and Links
client - the client's web browser
load balancer - distribute the traffic among servers
MySQL - database to store user and link information
User sends a POST request to the server and create a new record in the DB. The server creates a 16-bit hash for the url_link.
User sends a GET request to the server and receives a response with the link_url
Load balancer could use a Weighted Response Time algorithm to divide the traffic equally between the two servers.
I've chosen a relational database in order to store the data, because I can see that we are going to perform multiple joins between the tables and also the schema is clear enough from the beginning.
The sole load balancer is a single point of failure meaning.
We have only a single database that could be replicated.
Add caching - recently visited links could be cached so that we do not have to perform queries to the database to fetch those. Redis could be used as a technology for caching,