Requirements


Functional Requirements:


  • As a creator, I can create a short URL for a given long URL.
  • As a creator, I can delete a previously created URL
  • As a consumer, automatically redirect me to the long URL
  • Functional requirements not included here:
    • Ability for creators to edit their link
    • Ability for creators to see insights on their link (number of visits for instance)
    • Ability for creators to put a long URL based on the geography (or any other property from the client browser)
    • Ability for creators to pick the name of the URL



Non-Functional Requirements:


  • High availability as the availability of the ultimate page is the combination of the shortener URL service and the long URL too
  • Very low latency as you don't want
  • High scalability as some links can receive a lot of viewers
  • High short link variance as you don't want to have a short url collision
  • Eventual consistency: it's fine for links to take multiple minutes/seconds to be created/deleted
  • There must be an authentication/authorization system in place so creators can delete their links


API Design

  • POST /manage
    • Request headers:
      • OAuth2 Bearer token in authorization header
    • Request body:
      • { "longUrl": "{longUrl}" }
    • Response body:
      • { "id": "{createdId}" }
  • DELETE /manage/{shortURL}
    • Request headers:
      • OAuth2 Bearer token in authorization header
    • Response: 200
  • GET /{shortUrl}
    • Response: 301 Moved Permanently


High-Level Design

Use client-side browser caching as much as possible by returning a 301 Moved Permanently along with the appropriate Cache control headers so that for a given client, there is no further complete GET request on our side.


It's a low-write, heavy-read situation so we can use a SQL database to store the mapping between short and long URL acting as a source of truth.


We have two services:

  • Link Management service, in the control plane to add/delete links
  • Link Redirection service, in the data plane to get links and redirect users


We're always sending the same response so we could put a CDN in front



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.