Requirements


Functional Requirements:


  • Create a short URL for a given long URL.
  • Return the long URL associated with a given short URL.
  • Must prevent circular redirects
  • Use stop words to prevent improper short urls from being create



Non-Functional Requirements:


  • Must have high availability (99.999% uptime)
  • Must be able to support 1000 requests per second
  • Redirect responses must return within 10ms


API Design

  • /create - Takes in a URL, a shortcode, and creates a mapping
  • /lookup - Takes in shortcode from URL and does a lookup for full URL, returns redirect



High-Level Design

We will create a simple API that allows users to both create and lookup shortened URLS. The create endpoint must enforce the following rules: 1. A redirect cannot be circular and 2. Swear words and other bad terms are not allowed as shortcodes. The lookup endpoint should utilize a caching mechanism to return values for frequently searched for shortcodes. We will do this to help satisfy our requirement of 10ms redirect return times.




Detailed Component Design

Shortcode lookup - Needs to have a fast response time. Popular URLs will tax the system with repetitive URL lookups. We can utilize a caching layer to help reduce this. We should look into something like redis that can have a TTL on each lookup, and clear the cache when items become stale. If a shortcode is looked up the time to live can reset, thereby keeping the most used shortcodes hot. We will also have to plan for both DDOS attacks where shortcodes are hit abnormally high and another potential issue where all of our shortcodes are being accessed within short time intervals and filling up our available cache.