Requirements


Functional Requirements:


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



Non-Functional Requirements:


  • Low latency
  • Reliability



API Design

POST api/v1/shorten

request body: longUrl

response: shortenUrl


GET api/v1/shorten/{shortUrl}

response: return 302 + longUrl



High-Level Design

We need an API Gateway, so it can helps us with following topics:

  1. Throttling
  2. Auth
  3. IP whitelist


URL Redirection Service: GET API request will handled by this service, it will use read-through fetch the cache to see if the short url there, if not, it will query DB (NoSQL) and store the pair in the cache.


URL Generator Service: POST API request will handled by this service, it will generate an unique, short URL and store the in DB (NoSQL).


NoSQL: we choose to use NoSQL as we don't need ACID in this design and NoSQL is easy to do horizontal scaling.


Cache: LRU cache.



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.