Estimate the scale of the system you are going to design...
u
Client - makes a request to the server for either a shortened URL or an original URL. The client then redirects the user to an appropriate destination
Load balancer - distributes the traffic across multiple app servers
App server - If the request asks for a shortened URL, call shortened URL generation service for a unique URL. Once received this unique URL, make a call to the database and store the connection between shortened URL and original URL.
Shortened URL generation service - Given a URL, this service computes a unique shortened URL. To ensure that every URL is unique for the same origin, we can append the original URL with a number or key that will be auto incremented each time the service is trying to generate a new URL for this origin URL. This service likely has its own database that keeps track of the auto-increment number for each URL.
Database - Stores meta data such as user information and how many times a URL is clicked (for metrics). The key thing that we need to store is the mapping relationship between shortened_URL and original_URL. For scalability, we can go for a NoSQL database. It should also be replicated for data reliability. We can go with primary-replica replication to avoid data inconsistencies with multiple write databases.
Cache - Potentially placing a cache before the database so that "hot URLs" can be returned right away without making unnecessary calls to the database. This cache can be write-through so that whenever the data is updated in the database, it is also updated in the cache. The cache eviction policy can be LRU so less "hot URLs" can be automatically dropped.
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...
What are some future improvements you would make? How would you mitigate the failure scenario(s) you described above?