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.)...
  • Must be able to accommodate a high volume of requests.
  • Low latency to redirect shortened to the original URLs
  • High availability (Handle uptime during peak loads and potential outages)


API Design

Define the APIs expected from the system. This is your chance to analyze and define the read and write paths so that you can come up with the high-level design...

  • POST /shorten: This endpoint allows users to create a shortened URL providing an original URL. Upon creation, it returns a JSON response with the shortened URL. If a provided URL is invalid, returns an error code indicating invalid URL.
  • GET /original/{shortenedURL}: This endpoint allows users to retrieve the original URL. It acceps a JSON payload containing the shortened URL. If te shortened URL exists, returns a JSON response with the original URL. Otherwise, returns an error code indicating the shortened URL does not exist, or was deleted.


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.

A frontend is required for the user to interact with the system. A backend server hosts the API and the database. The database only needs to be accessed locally, and is only exposed through API calls.



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.

The user uses a front-end web interface as the primary way to interact with the system. The front-end contains an input entry point that takes in a URL.

The front-end queries the global API endpoint to create a URL, passing in the provided URL as a parameter. If the API returns an error, it handles it and returns a diagnosis message to the user.

A backend server runs the API. It validates the URLs for shortening and querying. The server also communicates with a central database cluster to create and retrieve entries when a shortened URL is created and queried.

The database runs in the same server as the API server, and is only exposed locally. This allows for greater security from network threats, but leads to more migration work when scaling horizontally. This can be mitigated with parameterizing connections, which can be transferred even after a database is migrated.