Requirements


Functional Requirements:


  • Create a short URL for a given long URL.
  • Return the long URL associated with a given short URL.
  • Facility to generate a customised shot URL



Non-Functional Requirements:


  • List the key non-functional requirements (eg low latency, scalability, reliability, etc.)...
  • low latency server as we need redirection
  • more scalable no-sql server
  • more reliable
  • highly available server like 99.99% of time
  • redis as we will be looking for the viral url multiple times.


API Design

Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...


post some-domain/longUrl/{longUrl} return shortUrl

get some-domain/{shortUrl} redirect longUrl



High-Level Design

Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.


post request comes to server with long url and server first checks in the db if that url is already present in the db or not. If present it returns the shortUrl token. If not it hashes the long url maybe using md5 or base62 encoding and generates a key or token and stores it in db and then returns this token to client


get request comes to server with short url from which server extracts the token and then searches the long url using it first in cache. If cache hits then it returns back the long url. If cache misses it checks in the db. If it's not even there it returns 404. If its there then it caches it and returns the token as short url.





Detailed Component Design

Deep dive into 2-3 key components. Explain how they work, how they scale, discuss tradeoffs, capacity, and any relevant algorithms or data structures.