Requirements


Functional Requirements:


  • Create a short URL for a given long URL.
  • Return the long URL associated with a given short URL.
  • Support custom URL



Non-Functional Requirements:


  • High availability
  • Low redirect latency
  • Horizontal scalability


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...

1) Endpoints

  • URL shortening endpoint
  • URL redirect endpoint
  • custom URL endpoint

2) HTTP methods

  • POST for creating a short URL
  • GET for retrieving the original URL from a short URL

3) Request and Response Formats

  • Expected input JSON for creating a short URL
  • Output format that includes shortened URL

4) Error Handling

5) Authentication and Security



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.


We need microservices where each service (Like URL creation and redirection) operates independent. To ensure unique identifiers to avoid collisions the service can create a hash. We need an API gateway to manage requests. To improve performance and reduce latency we can have a dedicated service for URL shortening that interacts with a caching layer. If a user requests that same URL we can respond back with the cache and have a TTL of 24 hours so that it doesn't become stale. In order to handle data storage, we can use a NoSQL database since we don't need a relational database and we can scale horizontal if needed.


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.