Requirements


Functional Requirements:


  • Create a short URL for a given long URL.
  • Return the long URL associated with a given short URL.
  • Saved the long URL to DB and the relationship 1 to 1.
  • System should support the ability to distribute URL shortening and redirection requests across multiple instances



Non-Functional Requirements:


  • scale horizontally by adding more instances of service seamlessly. System should detect with metrics the growing numbers of users that may need a new instance of the service to distribute traffic
  • latency
  • scalability by implement multiple instances of service across different geographic locations as needed
  • Helth checks of each service by metrics and alerts that can be detected and fixed.
  • Ensure high availability of the service by implement multiple instances of service across different geographic locations and add load balancing to distribute the traffic. Also adding metrics of request and response count
  • Achieve low latency by optimizing the search for long URLs and enabling fast redirection. The redirection time should be less than 500 milliseconds.


API Design


Request and Response for create short url

endpoint: "/api/v1/url"

method: POST

request body: "{"url": }"

response body: "{"short-url": }"


Request and Response to get long url

endpoint: "/api/v1/url/"

method: GET

response body: "{"url": }"



High-Level Design


Client should be able to send a request to our service by using the endpoints defined in API section.


Client will send the request to our system by first sending the request to Load Balancer so the request can be distributed if more than one instance of the service is created.


Service should be able to create a unique short version of the url passed in request to then save it in DB.


DB should have the relation between the long URL´s with the short URL created.


Depending on the operation, the Server should read from DB to get the long URL assigned to a short URL or save the relation.


The generate a short URL which will be unique to the long URL provided the service will use a hash function that will use SHA-256 to generate and ensure that same long URL will create the same short URL. The way to ensure the uniqueness of short URL assigned to a long URL with a strategy of open addressing


Service's storage layer is responsable of saving the relation between a given long URL and the short URL created


Service will implement a caching lookup by sending request to cahe system like Redis to get the URLs that are more in use between users. Using cache layer we will handle a high handle of requests for most common URL requested.


Load Balancer will send the request to an API Gateway that distribute the request to the specific service depending on the request. For the request togenerate a short URL it will send the request to Shortener Service that then will use ID Generator and to create the unique ID and then save it with both URL relation. After save it will cache the url for future reference. For the request to use a short URL and get the original URL, API Gateway will send the request to the Redirect Service which will send a response 3xx with the long URL so in that case client will redirect.


Creating another instance of the shortener service in a different location helps in any problem that crash our application.



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.


Shortener Service will be the main service with the business logic to save the relation between short and long URLs.


ID Generator Service will have the logic to generate the unique ID related to both URL versions.


Redirect Service will have the responsability to get the original URL from the short URL by lookup into cache and DB and then send a response with 3xx to redirect the client.