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:


  • reliability
  • low latency
  • scalability to different URL types
  • rate limiting
  • url shortening limit per user


API Design

string shortenURL(string url);

string getURL(string shortURL);



High-Level Design

Client sends API request to Server IP address. Rate Limiter filters requests. LB (Load Balancer) distributes the requests among API servers. API servers route the request to Query or Shorten Servers for URL based on the request type. Shorten Servers keep generating short hash keys and keep in Temp URL DB. When a shorten request comes, it immedeately picks one key from Temp URL DB and stores in URL DB as key-URL pair. and then replies Client with the shortened URL. When Query request comes the corresponding URL is picked from the URL DB relied to the Client.




Detailed Component Design

URL DB: No SQL DB with key-value storage

Shorten Servers: One thread continuously creating random strings of length 8 containing case sensitive english alphabets, and storing in Temp URL DB of capacity 1000. When Shorten request is recieved, one string is picked.