Create a short URL
Given a short URL, return the original long URL
Availability
Security (no malicious URLs)
Reliability
Estimate the scale of the system you are going to design...
CreateUrl(longUrl -> String)
Creates a new short url given a long url if there does not already exist a short url already
GetUrl(shortUrl -> String)
Retrieve the original url given a short url
We could use a noSQL key value DB. Such as AWS DynamoDB
Key: Short url
Value: Long url
Also, to reduce load on the DB we will also introduce a read through redis cache. The reason for this, is because if the data does not exist in the cache, we will update the DB and the cache together to improve performance.
Additionally, to provide high availability we will also do db replication, but specifically follow a master (write) -> slave (read) DB schema since this is a write heavy process
For this design, we should assume a large amount of traffic. Since we are concerned about security, we could apply an API Gateway to filter malicious URLs. Following this, we would route all traffic through a load balancer since we could have high throughput. We will be using a NoSQL database to store the new URLs since we do not need to worry about consistency. The data will never be updated since the short url created will be deterministic, so we can simply retain the data created.
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...
Depending on the algorithm used for creating short URLs we could run into issues of collision where 2 long urls share the same short.
Improving the process by which urls are generated to ensure that there are no collisions. This could be done by using a hashing algorithm that does not require significant computation power, such as MD5. If there is a collision, we can simply add salt and hash again. The salt generated would be using an internal method to maintain consistency and the deterministic nature of the url hashing