There needs to be below API endpoint -
Endpoint - api/v1/shorten
HTTP Request - POST
Json Body - { "url" : "www.example.com" }
Response -
Status Code - 201
{
shortenUrl : "tiny.ly/{shortCode}"
}
Endpoint - /{shortCode}
HTTP Request - GET]
Response -
Status Code - 302
Redirect Url - www.example.com
Load Balancer - There needs to be distribution of load among multiple servers. This will act as the entry point for the request and will route to the ideal server for reducing the latency.
Services - There are two API services available to enable the functionality -
Cache - Redis or similar cache mechanism needs to be implemented to cache the frequently accessed links.
Database - Need to use NoSQL database for easier read as the read service would be the more frequently used service.
Analytics Service - A analytics job needs to be configured to figure out the region, demographic and rate of click. This will be vital for collecting necessary analytics data.
Cache - The caching will be the vital service to enable low latency redirection. An algorithm needs to be implemented to determine a popularity score of a link. The analytics service would be useful for determining the popularity score. Based on the time when the users access the link, the region, and number of requests.
Database - The database needs to be sharded across cloud regions to reduce latency and database read time. Based on the geo-location of the link creator, the particular sharding region needs to be determined for storage.