Requirements


Functional Requirements:

  • Create a short URL for a given long URL.
  • Return the long URL associated with a given short URL.
  • Short URLs should map to only 1 long URL.



Non-Functional Requirements:


  • Low latency for the shortened URL resolution to long URL.
  • High availability for the creation and resolution of URLs. Users should be able to generate short URLs and use short URLs with little downtime.


API Design


We will need 2 endpoints, 1 for URL shortening, and 1 for resolving the shortened URL.


For the URL shortening endpoint, the request structure for the client is as follows:

  1. Long URL


The response structure for the server is as follows:

  1. Shortened URL


We will use a REST API over HTTP for the URL generation. This is so browsers will be able to natively deserialize the data, unlike gRPC. GraphQL adds unnecessary overhead as we are always requesting the same information.



For the URL resolving endpoint, we will pass in the shortened URL and return the long URL.



High-Level Design

Describe the overall system architecture. Identify the main components needed to solve the problem end-to-end. Use the diagramming tool to create a block diagram.


I will break this section down into two steps:

  1. The shortened URL generation
  2. The shortened URL resolution


For the shortened URL generation, we need a server layer to take in the long URL and check if there's an associated shortened URL. We will check in our database if we've already created a shortened URL for the given long URL. If we have not, then we will hash the long URL and write the association into our database.


Finally, we will return the hashed shortened URL to the client.


For the shortened URL resolution, we will first check a cache if the long URL is stored. If the long URL is not in the cache, we will read from the server to get the long URL associated with the short URL.



For both paths, we will introduce a load balancer for high availability.




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.


For the data storage layer,