Requirements


Functional Requirements:


  • Create a short URL for a given long URL.
  • Return the long URL associated with a given short URL.



Non-Functional Requirements:

  • High availability
  • Low Redirect Latency
  • Horizontal Scalability


API Design

RedirectUrls => /redirectUrls

/redirectUrls/{originalUrl}

/shorten


High-Level Design

We have users who wants to generate redirect urls for their long url. To create redirect urls we will need shortener service which will create shorten version of url, redirect service which then will map shorten to long version of url and sql database to store url mappings. Since one of non functional requirement is high availability we would use replication pattern of databases as well as replication of services with load balancer. To decrease latency we will use api gateway with caching mechanism such as AWS api gateway caching as well as cdn to deliver trafic with low latency to customers in different locations. If there are too many data to store we would use sharding mechanism on database and make shards based on original URL for storing redirect urls. Moreover we would use cache layer such for redirect service with redis with ttl policy based on anatytics which we gather with analytics service. To store urls in database we would use auto generation of uuid's in database such as postgresql. Also we would introduce Rate limiter for checking DDos attacks on our system and limit requests per minute.


Detailed Component Design

Key components of our system are Shortener service and Redirect Service. Shortener service would accept long url in body of post request to /shorten endpoint, create shorten version of url and send it to redirect service for storing in database. Redirect service would have two endpoints /redirectUrls for returning all redirect url mapping and /redirectUrls/{originalUrl} for mapping for concrete original Url. If there are too many mapping we would use pagination algorithm.