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:


    List the key non-functional requirements (eg low latency, scalability, reliability, etc.)...


API Design

The api can be simple, stateless, horizontally scalable.

It needs endpoints such as:


  • POST url/<long-url>
    • This endpoint will generate a short code, save it in the ID (as primary or indexed key) along with the long url
  • GET url?shortUrl=shortUrl
    • This endpoint is what the main page will use via JS at load time to redirect the user from the short url to the long url



High-Level Design


The high level design is at the diagram.

  • Landing page for ourTinyUrl.com. All requests land here, the client will query GET url?shortUrl, get a longUrl and redirect the user to the destination url
  • We have a scalable simple API with the 2 endpoints described above. We can have a load balancer in front of the API and as many instances of the API we want.
  • A DB that could be a cluster with master(writes) and slave (reads) architecture in case we need to escalate the DB layer too




Detailed Component Design


  • API
    • The 2 endpoints mentioned above
    • Scaling by having a load balancer in front of the API and as many API instances as needed
  • DB
    • 1 table to store short and long url mappings is all that is needed
    • Retrieval is O(1) already since we'll always query by an indexed column (short url code)
    • Could be scaled further by having a master (writes) / slave (reads) design