The system allows users to shorten URLs:
Performance requirements:
Availability:
Reliability:
Security:
Users and traffic growth:
Requests estimation
Storage requirements:
string CreateShortUrl(string longUrl)
string GetLongUrl(string shortUrl)
string DeleteShortUrl(string shortUrl)
bool SuspendShortUrl(string shortUrl, datetime until)
bool ChangeLongUrl(string shortUrl, string newLongUrl)
There is no very complex relationships in the data model. We can consider a NoSQL technology (key-value store for instance) in order to scale better.
The service is more read intensive than write so it can scale by adding more read replicas of the database.
The url lookup can be made faster by using a distributed cache.
Url entity
User entity
The client can be an anonymous user who clicked on a short URL or a authenticated user who wants to edit urls.
A load balancer is used to distribute evenly the requests from all users among serveral application servers. It could also be used as a rate-limiter.
Reading: servers will look for the urls first in the distributed cache and then in the database if the requested url isn't cached.
Writing: requests are pushed to a distributed queue so the service can handle peaks
Creation:
Retrieval:
We need to prioritize availability and partition tolerance in this case so we have to do some concession about consistency. Users must indeed:
But we can tolerate some delay before a newly created URL is readable from all clients (eventual consistency)
In case a database node fails:
If two short URLs are created with the same long URLs: