Requirements


Functional Requirements:


  • Create a short URL for a given long URL.
  • User can use the short URL to access the long URL



Non-Functional Requirements:


  • Low latency. this service is simple, 200ms is more than enough
  • High scalability, we can add read write replica to database, and make server stateless with many replicas, then a load balancer above


API Design


  • Create(longUrl string) string which accepts the long url and returns a short url. It also stores the mapping to its database
  • FindLongUrl(shortUrl string) string which accepts the short url and returns the long url.
  • Redirect(url string), redirect user to the page


High-Level Design


Client reaches to load balancer, and servers are stateless, then database has read write replicas.




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.


Servers can scale horizontally easily, just add servers into this and register them in load balancer. removing is also easy, remove the registration from load balancer, but we need to make sure no incoming traffic to the server we would like to remove.


load balancer can also be scaled vertically by adding more hardware or horizontally by adding more nodes. load balancers need to access the same server list, it can be an etcd or some databases.


Database can also be scaled horizontally or vertically. vertically by adding more hardward, horitonzally by adding more read write replicas.