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:


  • Low latency. We want those urls to be resolved fast.
  • Redirection if the id changes from a generated id to a custom-id.
  • scalability, How we we resolve urls fast
  • High availability
  • Not sure the eventual consistency.


API Design

From an API design POV it's quite simple. Let's start with the endpoingt:


  • POST /create
    • Body: url, possibly a custom id



High-Level Design


We are talking here about 5 layers.

  • The client layer
  • The global edge layer
  • The application layer
  • The Async workers layer
  • And the Data layer


All of them are connected to each other.

The Client layer makes HTTp requests to the CDN on the global edge layer, which is filtered by a WAF, the traffic then proceeds to the API Gateway which then routes to the write service and save it in a noSQL db for store mapping and redis for cache warming. Once a write happen, an async job also saves analytics on the analytics DB. When a client navigates to a URL, we're routes to the read service wich will first check the redis, and if there is a cache miss we're reading from the MongoDB


Detailed Component Design


  • Client: The client side makes the requests to create a new short URL